Skip to content

Commit cffe139

Browse files
committedDec 16, 2020
MySQL schema example
1 parent 7bbfebb commit cffe139

File tree

2 files changed

+112
-2
lines changed

2 files changed

+112
-2
lines changed
 

‎schema_example/mysql_ddl.sql

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
-- Example of schema
2+
-- The schema does not include any indexes ( except PK's )
3+
4+
-- Users
5+
CREATE TABLE users (
6+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
7+
account_id INTEGER,
8+
reputation INTEGER NOT NULL,
9+
views INTEGER DEFAULT 0,
10+
down_votes INTEGER DEFAULT 0,
11+
up_votes INTEGER DEFAULT 0,
12+
display_name VARCHAR(255) NOT NULL,
13+
location VARCHAR(512),
14+
profile_image_url VARCHAR(255),
15+
website_url VARCHAR(255),
16+
about_me TEXT,
17+
creation_date TIMESTAMP(3) NOT NULL,
18+
last_access_date TIMESTAMP(3) NOT NULL
19+
);
20+
21+
-- Posts
22+
CREATE TABLE posts (
23+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
24+
owner_user_id INTEGER,
25+
last_editor_user_id INTEGER,
26+
post_type_id SMALLINT NOT NULL,
27+
accepted_answer_id INTEGER,
28+
score INTEGER NOT NULL,
29+
parent_id INTEGER,
30+
view_count INTEGER,
31+
answer_count INTEGER DEFAULT 0,
32+
comment_count INTEGER DEFAULT 0,
33+
owner_display_name VARCHAR(64),
34+
last_editor_display_name VARCHAR(64),
35+
title VARCHAR(512),
36+
tags VARCHAR(512),
37+
content_license VARCHAR(64) NOT NULL,
38+
body TEXT,
39+
favorite_count INTEGER,
40+
creation_date TIMESTAMP(3) NOT NULL,
41+
community_owned_date TIMESTAMP(3),
42+
closed_date TIMESTAMP(3),
43+
last_edit_date TIMESTAMP(3),
44+
last_activity_date TIMESTAMP(3),
45+
46+
);
47+
48+
-- PostLinks
49+
CREATE TABLE post_links (
50+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
51+
related_post_id INTEGER NOT NULL,
52+
post_id INTEGER NOT NULL,
53+
link_type_id TINYINT NOT NULL,
54+
creation_date TIMESTAMP(3) NOT NULL
55+
);
56+
57+
-- PostHistory
58+
CREATE TABLE post_history (
59+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
60+
post_id INTEGER NOT NULL,
61+
user_id INTEGER,
62+
post_history_type_id TINYINT NOT NULL,
63+
user_display_name VARCHAR(64),
64+
content_license VARCHAR(64),
65+
revision_guid uuid,
66+
text TEXT,
67+
comment TEXT,
68+
creation_date TIMESTAMP(3) NOT NULL
69+
);
70+
71+
-- Comments
72+
CREATE TABLE comments (
73+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
74+
post_id INTEGER NOT NULL,
75+
user_id INTEGER,
76+
score TINYINT NOT NULL,
77+
content_license VARCHAR(64) NOT NULL,
78+
user_display_name VARCHAR(64),
79+
text TEXT,
80+
creation_date TIMESTAMP(3) NOT NULL
81+
);
82+
83+
-- Votes
84+
CREATE TABLE votes (
85+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
86+
user_id INTEGER,
87+
post_id INTEGER NOT NULL,
88+
vote_type_id TINYINT NOT NULL,
89+
bounty_amount TINYINT,
90+
creation_date TIMESTAMP(3) NOT NULL
91+
);
92+
93+
-- Badges
94+
CREATE TABLE badges (
95+
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
96+
user_id INTEGER NOT NULL,
97+
class TINYINT NOT NULL,
98+
name VARCHAR(64) NOT NULL,
99+
tag_based TINYINT(1) NOT NULL,
100+
date TIMESTAMP(3) NOT NULL
101+
);
102+
103+
-- Tags
104+
CREATE TABLE tags (
105+
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
106+
excerpt_post_id INTEGER,
107+
wiki_post_id INTEGER,
108+
tag_name VARCHAR(255) NOT NULL,
109+
count INTEGER DEFAULT 0
110+
);

‎schema_example/postgresql_ddl.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-- Example of schema
2-
-- Schema does not include any kind of indexes
2+
-- The schema does not include any indexes ( except PK's )
33

44
-- Users
55
CREATE TABLE users (
@@ -96,7 +96,7 @@ CREATE TABLE badges (
9696
class SMALLINT NOT NULL,
9797
name VARCHAR(64) NOT NULL,
9898
tag_based BOOL NOT NULL,
99-
date timestamp NOT NULL
99+
date TIMESTAMP NOT NULL
100100
);
101101

102102
-- Tags

0 commit comments

Comments
 (0)
Please sign in to comment.