-
Notifications
You must be signed in to change notification settings - Fork 4
/
schema.py
69 lines (60 loc) · 1.81 KB
/
schema.py
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
import pymysql
from config.database import HOST, PORT, PASSWORD, USER, DATABASE
'''
数据库迁移脚本,一键建表
'''
db = pymysql.Connect(
host=HOST,
port=PORT,
user=USER,
passwd=PASSWORD,
db=DATABASE,
charset='utf8'
)
cursor = db.cursor()
sql = """
DROP TABLE IF EXISTS `issue`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `issue` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`source` varchar(45) DEFAULT NULL,
`type` varchar(45) DEFAULT NULL,
`No` varchar(45) NOT NULL,
`opened_time` varchar(45) DEFAULT NULL,
`latest_time` varchar(45) DEFAULT NULL,
`comment_number` varchar(255) DEFAULT NULL,
`link` varchar(255) DEFAULT NULL,
`answered` varchar(45) NOT NULL,
`status` varchar(45) NOT NULL,
`author` varchar(255) NOT NULL,
`content` mediumtext,
PRIMARY KEY (`id`),
UNIQUE KEY `No_UNIQUE` (`No`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `pull`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `pull` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`source` varchar(45) DEFAULT NULL,
`type` varchar(45) DEFAULT NULL,
`No` varchar(45) NOT NULL,
`opened_time` varchar(45) DEFAULT NULL,
`latest_time` varchar(45) DEFAULT NULL,
`link` varchar(255) DEFAULT NULL,
`answered` varchar(45) NOT NULL,
`status` varchar(45) NOT NULL,
`author` varchar(255) NOT NULL,
`content` mediumtext,
PRIMARY KEY (`id`),
UNIQUE KEY `No_UNIQUE` (`No`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;"""
try:
cursor.execute(sql)
db.commit()
except Exception as e:
print("Mysql create table error: %s" % e)
db.close()