-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_create.py
130 lines (113 loc) · 3.41 KB
/
db_create.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
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
from __future__ import print_function
import utils
def create_frame(crs):
sql = "drop table if exists frame;"
crs.execute(sql)
sql = """
create table frame (
pkid VARCHAR(36) NOT NULL PRIMARY KEY,
name VARCHAR(256) NOT NULL,
frameset_id VARCHAR(36) DEFAULT NULL,
album_id VARCHAR(36),
description VARCHAR(256),
orientation ENUM('H', 'V', 'S') NOT NULL DEFAULT 'H',
interval_time SMALLINT UNSIGNED NOT NULL DEFAULT 1,
interval_units VARCHAR(16) NOT NULL DEFAULT 'hours',
variance_pct SMALLINT DEFAULT 10,
halflife_interval SMALLINT DEFAULT 0,
shutdown TINYINT(1) DEFAULT 0,
brightness DECIMAL (4,3) UNSIGNED DEFAULT 1.0,
contrast DECIMAL (4,3) UNSIGNED DEFAULT 1.0,
saturation DECIMAL (4,3) UNSIGNED DEFAULT 1.0,
freespace BIGINT DEFAULT 9999,
ip VARCHAR(16),
updated TIMESTAMP,
log_level ENUM('DEBUG', 'INFO', 'WARN', 'ERROR') NOT NULL DEFAULT 'INFO'
);
"""
crs.execute(sql)
def create_frameset(crs):
sql = "drop table if exists frameset;"
crs.execute(sql)
sql = """
create table frameset (
pkid VARCHAR(36) NOT NULL PRIMARY KEY,
name VARCHAR(256) NOT NULL,
user_id VARCHAR(36) DEFAULT NULL,
album_id VARCHAR(36) DEFAULT NULL,
description VARCHAR(256),
orientation ENUM('H', 'V', 'S') NOT NULL DEFAULT 'H',
interval_time SMALLINT UNSIGNED NOT NULL DEFAULT 1,
interval_units VARCHAR(16) NOT NULL DEFAULT 'hours',
variance_pct INT DEFAULT NULL DEFAULT 10,
halflife_interval SMALLINT DEFAULT 0,
updated TIMESTAMP
);
"""
crs.execute(sql)
def create_image(crs):
sql = "drop table if exists image;"
crs.execute(sql)
sql = """
create table image (
pkid VARCHAR(36) NOT NULL PRIMARY KEY,
keywords VARCHAR(256),
name VARCHAR(256) NOT NULL,
width INT NOT NULL,
height INT NOT NULL,
orientation ENUM('H', 'V', 'S') NOT NULL,
imgtype VARCHAR(6),
size INT,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP
);
"""
crs.execute(sql)
utils.update_img_db(cursor=crs)
def create_album(crs):
sql = "drop table if exists album;"
crs.execute(sql)
sql = """
create table album (
pkid VARCHAR(36) NOT NULL PRIMARY KEY,
name VARCHAR(256) NOT NULL,
orientation ENUM('H', 'V', 'S') NOT NULL,
parent_id VARCHAR(36),
smart TINYINT(1) DEFAULT 0,
updated TIMESTAMP
);
"""
crs.execute(sql)
def create_album_image(crs):
sql = "drop table if exists album_image;"
crs.execute(sql)
sql = """
create table album_image (
album_id VARCHAR(36),
image_id VARCHAR(36),
PRIMARY KEY (album_id, image_id)
);
"""
crs.execute(sql)
def create_rule(crs):
sql = "drop table if exists rule;"
crs.execute(sql)
sql = """
create table rule (
pkid VARCHAR(36) NOT NULL PRIMARY KEY,
album_id VARCHAR(36),
rule VARCHAR(256),
updated TIMESTAMP
);
"""
crs.execute(sql)
def main(crs):
create_frame(crs)
create_frameset(crs)
create_image(crs)
create_album(crs)
create_album_image(crs)
crs.connection.commit()
if __name__ == "__main__":
with utils.DbCursor() as crs:
main(crs)