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

Commit0c53a40

Browse files
Step 1. Initialize DB
1 parent31d6a2c commit0c53a40

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##Инициализация схемы БД
2+
3+
```bash
4+
psql postgresql://root:root@localhost:5432/blog
5+
6+
CREATE TABLE posts (
7+
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
8+
created_by VARCHAR(255),
9+
created_date TIMESTAMP WITHOUT TIME ZONE,
10+
last_modified_by VARCHAR(255),
11+
last_modified_date TIMESTAMP WITHOUT TIME ZONE,
12+
title VARCHAR(255) NOT NULL,
13+
text OID NOT NULL,
14+
published_at TIMESTAMP WITHOUT TIME ZONE,
15+
author_id BIGINT NOT NULL,
16+
CONSTRAINT pk_posts PRIMARY KEY (id)
17+
);
18+
19+
CREATE TABLE users (
20+
id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
21+
created_by VARCHAR(255),
22+
created_date TIMESTAMP WITHOUT TIME ZONE,
23+
last_modified_by VARCHAR(255),
24+
last_modified_date TIMESTAMP WITHOUT TIME ZONE,
25+
first_name VARCHAR(255) NOT NULL,
26+
last_name VARCHAR(255) NOT NULL,
27+
CONSTRAINT pk_users PRIMARY KEY (id)
28+
);
29+
30+
CREATE INDEX idx_user_names ON users(first_name, last_name);
31+
32+
ALTER TABLE posts ADD CONSTRAINT FK_POSTS_ON_AUTHOR FOREIGN KEY (author_id) REFERENCES users (id);
33+
34+
\q
35+
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp