Definition
- Diagram
- MySQL
CREATE TABLE IF NOT EXISTS `categories` (
`id` bigint(20) unsigned NOT NULL,
`ref` bigint(20) unsigned NOT NULL COMMENT 'parent category id',
`key` varchar(32) NOT NULL COMMENT 'snake name',
`category_name` varchar(127) NOT NULL,
`status` int(10) NOT NULL COMMENT '-1 deleted 0 pendding 1 valid',
`created_at` timestamp NULL,
`updated_at` timestamp NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE IF NOT EXISTS `tags` (
`id` bigint(20) unsigned NOT NULL,
`ref` bigint(20) unsigned NOT NULL COMMENT 'parent tag id',
`key` varchar(32) NOT NULL COMMENT 'snake name',
`tag_name` varchar(127) NOT NULL,
`status` int(10) NOT NULL COMMENT '-1 deleted 0 pendding 1 valid',
`created_at` timestamp NULL,
`updated_at` timestamp NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE IF NOT EXISTS `articles` (
`id` bigint(20) unsigned NOT NULL,
`category_id` bigint(20) unsigned NOT NULL,
`user_id` bigint(20) unsigned NOT NULL COMMENT 'createdBy',
`key` varchar(32) NOT NULL COMMENT 'snake name',
`article_title` varchar(127) NOT NULL,
`article_content` text NOT NULL,
`status` int(10) NOT NULL COMMENT '-1 deleted 0 pendding 1 valid',
`created_at` timestamp NULL,
`updated_at` timestamp NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_articles_category_id` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)
);
CREATE TABLE IF NOT EXISTS `article_tag` (
`article_id` bigint(20) unsigned NOT NULL,
`tag_id` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`article_id`, `tag_id`),
CONSTRAINT `fk_article_tag_article_id` FOREIGN KEY (`article_id`) REFERENCES `articles` (`id`),
CONSTRAINT `fk_article_tag_tag_id` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`)
);
CREATE TABLE IF NOT EXISTS `comments` (
`id` bigint(20) unsigned NOT NULL,
`article_id` bigint(20) unsigned NOT NULL,
`user_id` bigint(20) unsigned NOT NULL COMMENT 'createdBy',
`key` varchar(32) NOT NULL COMMENT 'snake name',
`comment_title` varchar(127) NOT NULL,
`comment_content` text NOT NULL,
`status` int(10) NOT NULL COMMENT '-1 deleted 0 pendding 1 valid',
`created_at` timestamp NULL,
`updated_at` timestamp NULL,
PRIMARY KEY (`id`),
CONSTRAINT `fk_comments_article_id` FOREIGN KEY (`article_id`) REFERENCES `articles` (`id`)
);
Category
AttributeName | AttributeType | ColumnName | DataType | NotNull | Comment |
---|---|---|---|---|---|
ID | uint64 | id | bigint(20) unsigned | true | |
Ref | uint64 | ref | bigint(20) unsigned | true | parent category id |
Key | string | key | varchar(32) | true | snake name |
CategoryName | string | category_name | varchar(127) | true | |
Status | int | status | int(10) | true | -1 deleted 0 pendding 1 valid |
CreatedAt | *time.Time | created_at | timestamp | false | |
UpdatedAt | *time.Time | updated_at | timestamp | false |
Tag
AttributeName | AttributeType | ColumnName | DataType | NotNull | Comment |
---|---|---|---|---|---|
ID | uint64 | id | bigint(20) unsigned | true | |
Ref | uint64 | ref | bigint(20) unsigned | true | parent tag id |
Key | string | key | varchar(32) | true | snake name |
TagName | string | tag_name | varchar(127) | true | |
Status | int | status | int(10) | true | -1 deleted 0 pendding 1 valid |
CreatedAt | *time.Time | created_at | timestamp | false | |
UpdatedAt | *time.Time | updated_at | timestamp | false |
Article
AttributeName | AttributeType | ColumnName | DataType | NotNull | Comment |
---|---|---|---|---|---|
ID | uint64 | id | bigint(20) unsigned | true | |
CategoryID | uint64 | category_id | bigint(20) unsigned | true | |
UserID | uint64 | user_id | bigint(20) unsigned | true | createdBy |
Key | string | key | varchar(32) | true | snake name |
ArticleTitle | string | article_title | varchar(127) | true | |
ArticleContent | string | article_content | text | true | |
Status | int | status | int(10) | true | -1 deleted 0 pendding 1 valid |
CreatedAt | *time.Time | created_at | timestamp | false | |
UpdatedAt | *time.Time | updated_at | timestamp | false |
ArticleTag
AttributeName | AttributeType | ColumnName | DataType | NotNull | Comment |
---|---|---|---|---|---|
ArticleID | uint64 | article_id | bigint(20) unsigned | true | |
TagID | uint64 | tag_id | bigint(20) unsigned | true |
Comment
AttributeName | AttributeType | ColumnName | DataType | NotNull | Comment |
---|---|---|---|---|---|
ID | uint64 | id | bigint(20) unsigned | true | |
ArticleID | uint64 | article_id | bigint(20) unsigned | true | |
UserID | uint64 | user_id | bigint(20) unsigned | true | createdBy |
Key | string | key | varchar(32) | true | snake name |
CommentTitle | string | comment_title | varchar(127) | true | |
CommentContent | string | comment_content | text | true | |
Status | int | status | int(10) | true | -1 deleted 0 pendding 1 valid |
CreatedAt | *time.Time | created_at | timestamp | false | |
UpdatedAt | *time.Time | updated_at | timestamp | false |