-
Notifications
You must be signed in to change notification settings - Fork 3
/
DiglotModel_create.sql
134 lines (114 loc) · 4.73 KB
/
DiglotModel_create.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
-- Created by Vertabelo (http://vertabelo.com)
-- Last modification date: 2016-05-05 20:03:17.597
-- tables
-- Table: Article
CREATE TABLE Article (
id int NOT NULL DEFAULT 0 AUTO_INCREMENT,
title varchar(100) NOT NULL,
category varchar(100) NOT NULL,
url varchar(500) NOT NULL,
id_status int NOT NULL DEFAULT 0,
date_create timestamp NULL,
date_modified timestamp NULL ON UPDATE CURRENT_TIMESTAMP,
date_deleted timestamp NOT NULL,
CONSTRAINT Article_pk PRIMARY KEY (id)
) COMMENT ''
COMMENT 'Статья';
-- Table: Comments
CREATE TABLE Comments (
id int NOT NULL DEFAULT 0 AUTO_INCREMENT,
id_person int NOT NULL,
id_article int NOT NULL,
comment text NULL,
date_create timestamp NULL,
CONSTRAINT Comments_pk PRIMARY KEY (id)
) COMMENT ''
COMMENT 'Комментарии к статьям';
-- Table: Paragraph
CREATE TABLE Paragraph (
id int NOT NULL DEFAULT 0 AUTO_INCREMENT,
id_article int NOT NULL,
paragraph text NULL,
date_modified timestamp NULL ON UPDATE CURRENT_TIMESTAMP,
CONSTRAINT Paragraph_pk PRIMARY KEY (id)
) COMMENT ''
COMMENT 'Абзац в статье, который может быть и ссылкой на картинку';
-- Table: Person
CREATE TABLE Person (
id int NOT NULL DEFAULT 0 AUTO_INCREMENT,
login text NULL,
password varchar(40) NULL,
name text NULL,
description text NOT NULL,
url varchar(500) NOT NULL,
date_registry timestamp NULL,
CONSTRAINT Person_pk PRIMARY KEY (id)
) COMMENT ''
COMMENT 'Автор, читатель или редактор статьи';
-- Table: Selected_article
CREATE TABLE Selected_article (
id int NOT NULL DEFAULT 0 AUTO_INCREMENT,
id_person int NOT NULL,
id_article int NOT NULL,
date_selected timestamp NULL,
date_deleted timestamp NOT NULL,
CONSTRAINT Selected_article_pk PRIMARY KEY (id)
);
-- Table: Selected_author
CREATE TABLE Selected_author (
id int NOT NULL DEFAULT 0 AUTO_INCREMENT,
id_person int NOT NULL,
id_author int NOT NULL,
date_selected timestamp NULL,
date_deleted timestamp NOT NULL,
CONSTRAINT Selected_author_pk PRIMARY KEY (id)
) COMMENT ''
COMMENT 'Избранный автор';
-- Table: Selected_paragraph
CREATE TABLE Selected_paragraph (
id int NOT NULL DEFAULT 0 AUTO_INCREMENT,
id_person int NOT NULL,
id_article int NOT NULL,
date_modified timestamp NULL ON UPDATE CURRENT_TIMESTAMP,
date_deleted timestamp NOT NULL,
CONSTRAINT Selected_paragraph_pk PRIMARY KEY (id)
);
-- Table: status
CREATE TABLE status (
id int NOT NULL DEFAULT 0,
status varchar(20) NULL DEFAULT Черновик,
CONSTRAINT status_pk PRIMARY KEY (id)
) COMMENT ''
COMMENT 'У статьи статус : черновик, опубликована, удалена';
-- foreign keys
-- Reference: Article_status (table: Article)
ALTER TABLE Article ADD CONSTRAINT Article_status FOREIGN KEY Article_status (id_status)
REFERENCES status (id);
-- Reference: Comments_Article (table: Comments)
ALTER TABLE Comments ADD CONSTRAINT Comments_Article FOREIGN KEY Comments_Article (id_article)
REFERENCES Article (id);
-- Reference: Comments_Person (table: Comments)
ALTER TABLE Comments ADD CONSTRAINT Comments_Person FOREIGN KEY Comments_Person (id_person)
REFERENCES Person (id);
-- Reference: Paragraph_Article (table: Paragraph)
ALTER TABLE Paragraph ADD CONSTRAINT Paragraph_Article FOREIGN KEY Paragraph_Article (id_article)
REFERENCES Article (id);
-- Reference: Selected_article_Article (table: Selected_article)
ALTER TABLE Selected_article ADD CONSTRAINT Selected_article_Article FOREIGN KEY Selected_article_Article (id_article)
REFERENCES Article (id);
-- Reference: Selected_article_Person (table: Selected_article)
ALTER TABLE Selected_article ADD CONSTRAINT Selected_article_Person FOREIGN KEY Selected_article_Person (id_person)
REFERENCES Person (id);
-- Reference: Selected_author_Person (table: Selected_author)
ALTER TABLE Selected_author ADD CONSTRAINT Selected_author_Person FOREIGN KEY Selected_author_Person (id_author)
REFERENCES Person (id);
-- Reference: Selected_author_Person1 (table: Selected_author)
ALTER TABLE Selected_author ADD CONSTRAINT Selected_author_Person1 FOREIGN KEY Selected_author_Person1 (id_person)
REFERENCES Person (id);
-- Reference: Selected_paragraph_Article (table: Selected_paragraph)
ALTER TABLE Selected_paragraph ADD CONSTRAINT Selected_paragraph_Article FOREIGN KEY Selected_paragraph_Article (id_article)
REFERENCES Article (id);
-- Reference: Selected_paragraph_Person (table: Selected_paragraph)
ALTER TABLE Selected_paragraph ADD CONSTRAINT Selected_paragraph_Person FOREIGN KEY Selected_paragraph_Person (id_person)
REFERENCES Person (id);
-- End of file.