Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1724eda

Browse files
Step 4. Modify DB schema: add comments table, adjust users table
1 parent1bc9f61 commit1724eda

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎generate-entities-from-db/blog/SCRIPTS.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,45 @@ ALTER TABLE posts ADD CONSTRAINT FK_POSTS_ON_AUTHOR FOREIGN KEY (author_id) REFE
3333

3434
\q
3535
```
36+
37+
##Изменение схемы БД
38+
39+
```bash
40+
psql postgresql://root:root@localhost:5432/blog
41+
42+
ALTER TABLE users
43+
ADD email VARCHAR(255);
44+
45+
ALTER TABLE users
46+
ADD last_activity TIMESTAMP WITHOUT TIME ZONE;
47+
48+
CREATE TABLE comments
49+
(
50+
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
51+
created_by VARCHAR(255),
52+
created_date TIMESTAMP WITHOUT TIME ZONE,
53+
last_modified_by VARCHAR(255),
54+
last_modified_date TIMESTAMP WITHOUT TIME ZONE,
55+
author_id BIGINT NOT NULL,
56+
text VARCHAR(255),
57+
CONSTRAINT pk_comments PRIMARY KEY (id)
58+
);
59+
60+
CREATE TABLE comments_posts
61+
(
62+
comments_id BIGINT NOT NULL,
63+
posts_id BIGINT NOT NULL,
64+
CONSTRAINT pk_comments_posts PRIMARY KEY (comments_id, posts_id)
65+
);
66+
67+
ALTER TABLE comments
68+
ADD CONSTRAINT FK_COMMENT_ON_AUTHOR FOREIGN KEY (author_id) REFERENCES users (id);
69+
70+
ALTER TABLE comments_posts
71+
ADD CONSTRAINT fk_compos_on_comments FOREIGN KEY (comments_id) REFERENCES comments (id);
72+
73+
ALTER TABLE comments_posts
74+
ADD CONSTRAINT fk_compos_on_post FOREIGN KEY (posts_id) REFERENCES posts (id);
75+
76+
\q
77+
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp