initial release
This commit is contained in:
commit
8d86bdd33d
45 changed files with 2558 additions and 0 deletions
40
db/migrations/20220310_init.sql
Normal file
40
db/migrations/20220310_init.sql
Normal file
|
@ -0,0 +1,40 @@
|
|||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
CREATE TABLE IF NOT EXISTS app_users (
|
||||
id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||
name character varying(50),
|
||||
created_at timestamp without time zone NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT unique_name UNIQUE (name),
|
||||
CONSTRAINT app_user_pkey PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS public_keys (
|
||||
id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||
user_id uuid NOT NULL,
|
||||
public_key varchar(2048) NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT user_public_keys_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT unique_key_for_user UNIQUE (user_id, public_key),
|
||||
CONSTRAINT fk_user_public_keys_owner
|
||||
FOREIGN KEY(user_id)
|
||||
REFERENCES app_users(id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||
user_id uuid NOT NULL,
|
||||
title character varying(255) NOT NULL,
|
||||
text text NOT NULL DEFAULT '',
|
||||
publish_at timestamp without time zone NOT NULL DEFAULT NOW(),
|
||||
created_at timestamp without time zone NOT NULL DEFAULT NOW(),
|
||||
updated_at timestamp without time zone NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT posts_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT unique_title_for_user UNIQUE (user_id, title),
|
||||
CONSTRAINT fk_posts_app_users
|
||||
FOREIGN KEY(user_id)
|
||||
REFERENCES app_users(id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE
|
||||
);
|
8
db/migrations/20220422_add_desc_to_user_and_post.sql
Normal file
8
db/migrations/20220422_add_desc_to_user_and_post.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
ALTER TABLE app_users ADD COLUMN bio character varying(150) NOT NULL DEFAULT '';
|
||||
ALTER TABLE posts ADD COLUMN description character varying(150) NOT NULL DEFAULT '';
|
||||
ALTER TABLE posts ADD COLUMN filename character varying(255);
|
||||
|
||||
UPDATE posts SET filename = title;
|
||||
|
||||
ALTER TABLE posts ADD CONSTRAINT unique_filename_for_user UNIQUE (user_id, filename);
|
||||
ALTER TABLE posts DROP CONSTRAINT unique_title_for_user;
|
2
db/migrations/20220426_add_index_for_filename.sql
Normal file
2
db/migrations/20220426_add_index_for_filename.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
CREATE INDEX posts_filename ON posts USING btree(filename);
|
||||
ALTER TABLE app_users DROP COLUMN bio;
|
1
db/migrations/20220427_username_to_lower.sql
Normal file
1
db/migrations/20220427_username_to_lower.sql
Normal file
|
@ -0,0 +1 @@
|
|||
UPDATE app_users SET name = LOWER(name) WHERE name != LOWER(name);
|
5
db/migrations/20220523_timestamp_with_tz.sql
Normal file
5
db/migrations/20220523_timestamp_with_tz.sql
Normal file
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE posts ALTER COLUMN updated_at TYPE timestamp WITH TIME ZONE USING updated_at AT TIME ZONE 'UTC';
|
||||
ALTER TABLE posts ALTER COLUMN publish_at TYPE timestamp WITH TIME ZONE USING publish_at AT TIME ZONE 'UTC';
|
||||
ALTER TABLE posts ALTER COLUMN created_at TYPE timestamp WITH TIME ZONE USING created_at AT TIME ZONE 'UTC';
|
||||
ALTER TABLE app_users ALTER COLUMN created_at TYPE timestamp WITH TIME ZONE USING created_at AT TIME ZONE 'UTC';
|
||||
ALTER TABLE public_keys ALTER COLUMN created_at TYPE timestamp WITH TIME ZONE USING created_at AT TIME ZONE 'UTC';
|
1
db/setup.sql
Normal file
1
db/setup.sql
Normal file
|
@ -0,0 +1 @@
|
|||
CREATE DATABASE "pastes" OWNER "postgres";
|
3
db/teardown.sql
Normal file
3
db/teardown.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
DROP TABLE posts CASCADE;
|
||||
DROP TABLE app_users CASCADE;
|
||||
DROP TABLE public_keys CASCADE;
|
Loading…
Add table
Add a link
Reference in a new issue