Skip to content

Commit ce50592

Browse files
committedOct 25, 2020
Update DB to Postgres 13, add Articles table schema
1 parent 4202f29 commit ce50592

11 files changed

+70
-14
lines changed
 
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
DROP INDEX IF EXISTS ix_auth_email;
1+
DROP INDEX IF EXISTS ix_auth_profile;
22

33
DROP TABLE IF EXISTS auth;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DROP INDEX IF EXISTS ix_article_author;
2+
3+
DROP TABLE IF EXISTS article;

‎db/migration/h2/V1_0__Create_Profile_table.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- Table: Profile (User + Author)
22
-- ~~~~~~
3-
CREATE TABLE IF NOT EXISTS profile(
3+
CREATE TABLE IF NOT EXISTS profile (
44
id BIGSERIAL NOT NULL,
55
username VARCHAR NOT NULL,
66
email VARCHAR NOT NULL,
+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
-- Table: Authentication
22
-- ~~~~~~
3-
CREATE TABLE IF NOT EXISTS auth(
3+
CREATE TABLE IF NOT EXISTS auth (
44
id BIGSERIAL NOT NULL,
55
profile_id BIGINT NOT NULL,
66
password VARCHAR,
77
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
88
modified_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
99
CONSTRAINT pk_auth_id PRIMARY KEY (id),
10-
CONSTRAINT fk_auth_profile FOREIGN KEY (profile_id) REFERENCES profile (id)
10+
CONSTRAINT fk_auth_profile FOREIGN KEY (profile_id)
11+
REFERENCES profile (id)
12+
ON DELETE CASCADE
1113
);
14+
15+
CREATE INDEX IF NOT EXISTS ix_auth_profile
16+
ON auth (profile_id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Table: Article
2+
-- ~~~~~~
3+
CREATE TABLE IF NOT EXISTS article (
4+
id BIGSERIAL NOT NULL,
5+
slug VARCHAR NOT NULL,
6+
title VARCHAR NOT NULL,
7+
description VARCHAR NOT NULL,
8+
body VARCHAR NOT NULL,
9+
author_id BIGINT NOT NULL,
10+
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
11+
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
12+
CONSTRAINT pk_article_id PRIMARY KEY (id),
13+
CONSTRAINT uq_article_slug UNIQUE (author_id, slug),
14+
CONSTRAINT fk_article_profile FOREIGN KEY (author_id)
15+
REFERENCES profile (id)
16+
ON DELETE CASCADE
17+
);
18+
19+
CREATE INDEX IF NOT EXISTS ix_article_author
20+
ON article (author_id);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
DROP INDEX IF EXISTS ix_auth_email;
1+
DROP INDEX IF EXISTS ix_auth_profile;
22

33
DROP TABLE IF EXISTS auth;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DROP INDEX IF EXISTS ix_article_author;
2+
3+
DROP TABLE IF EXISTS article;

‎db/migration/postgresql/V1_0__Create_Profile_table.sql

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-- Table: Profile (User + Author)
22
-- ~~~~~~
3-
CREATE TABLE IF NOT EXISTS profile(
3+
CREATE TABLE IF NOT EXISTS profile (
44
id BIGSERIAL NOT NULL,
5-
username VARCHAR NOT NULL,
6-
email VARCHAR NOT NULL,
7-
bio VARCHAR,
8-
image VARCHAR,
5+
username TEXT NOT NULL,
6+
email TEXT NOT NULL,
7+
bio TEXT,
8+
image TEXT,
99
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
1010
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
1111
CONSTRAINT pk_profile_id PRIMARY KEY (id),
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
-- Table: Authentication
22
-- ~~~~~~
3-
CREATE TABLE IF NOT EXISTS auth(
3+
CREATE TABLE IF NOT EXISTS auth (
44
id BIGSERIAL NOT NULL,
55
profile_id BIGINT NOT NULL,
6-
password VARCHAR,
6+
password TEXT,
77
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
88
modified_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
99
CONSTRAINT pk_auth_id PRIMARY KEY (id),
10-
CONSTRAINT fk_auth_profile FOREIGN KEY (profile_id) REFERENCES profile (id)
10+
CONSTRAINT fk_auth_profile FOREIGN KEY (profile_id)
11+
REFERENCES profile (id)
12+
ON DELETE CASCADE
1113
);
14+
15+
CREATE INDEX IF NOT EXISTS ix_auth_profile
16+
ON auth (profile_id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Table: Article
2+
-- ~~~~~~
3+
CREATE TABLE IF NOT EXISTS article (
4+
id BIGSERIAL NOT NULL,
5+
slug TEXT NOT NULL,
6+
title TEXT NOT NULL,
7+
description TEXT NOT NULL,
8+
body TEXT NOT NULL,
9+
author_id BIGINT NOT NULL,
10+
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
11+
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
12+
CONSTRAINT pk_article_id PRIMARY KEY (id),
13+
CONSTRAINT uq_article_slug UNIQUE (author_id, slug),
14+
CONSTRAINT fk_article_profile FOREIGN KEY (author_id)
15+
REFERENCES profile (id)
16+
ON DELETE CASCADE
17+
);
18+
19+
CREATE INDEX IF NOT EXISTS ix_article_author
20+
ON article (author_id);

‎docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ services:
33
db:
44
environment:
55
- POSTGRES_PASSWORD=S3cret!
6-
image: postgres:12-alpine
6+
image: postgres:13-alpine
77
ports:
88
- "5432:5432"
99
volumes:

0 commit comments

Comments
 (0)
Please sign in to comment.