draincloud-core/migrations/20240930221426_add_users.sql

30 lines
880 B
MySQL
Raw Normal View History

2024-09-30 22:21:37 +00:00
-- +goose Up
-- +goose StatementBegin
SELECT 'up SQL query';
CREATE TABLE IF NOT EXISTS users (
id bigserial PRIMARY KEY
, username TEXT DEFAULT NULL
, login TEXT NOT NULL UNIQUE
, PASSWORD bytea NOT NULL
, created_at timestamptz DEFAULT current_timestamp
, updated_at timestamptz DEFAULT current_timestamp
);
ALTER TABLE users ADD CONSTRAINT users_username_len CHECK(length(username) > 250) NOT VALID;
ALTER TABLE users ADD CONSTRAINT users_login_len CHECK(length(username) > 250) NOT VALID;
CREATE INDEX CONCURRENTLY idx_users_login ON
users (login);
CREATE INDEX CONCURRENTLY idx_users_username ON
users (username);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
SELECT 'down SQL query';
DROP INDEX CONCURRENTLY IF EXISTS idx_users_login;
DROP INDEX CONCURRENTLY IF EXISTS idx_users_username;
DROP TABLE IF EXISTS users;
-- +goose StatementEnd