-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_validation.go
64 lines (50 loc) · 1.32 KB
/
sql_validation.go
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
package main
import (
"database/sql"
)
func createLoggedUsersTable(db *sql.DB) error {
_, err := db.Exec("CREATE TABLE IF NOT EXISTS " + loggedUsersTable + " (" +
"id SERIAL," +
"\"user\" VARCHAR(8) NOT NULL UNIQUE," +
"token VARCHAR(60) NOT NULL UNIQUE," +
"last_updated TIMESTAMP NOT NULL," +
"PRIMARY KEY (id));")
return err
}
func createAttachmentsTable(db *sql.DB) error {
_, err := db.Exec("CREATE TABLE IF NOT EXISTS " + attachmentsTable + " (" +
"id SERIAL," +
"att_id VARCHAR(256) NOT NULL UNIQUE," +
"fname VARCHAR(256) NOT NULL," +
"content_type VARCHAR(128) NOT NULL," +
"last_updated TIMESTAMP NOT NULL," +
"PRIMARY KEY (id));")
return err
}
func createMonthCacheTable(db *sql.DB) error {
_, err := db.Exec("CREATE TABLE IF NOT EXISTS " + monthCacheTable + " (" +
"id SERIAL," +
"\"user\" VARCHAR(8) NOT NULL," +
"start TIMESTAMP NOT NULL," +
"\"end\" TIMESTAMP NOT NULL," +
"contents TEXT NOT NULL," +
"last_updated TIMESTAMP NOT NULL," +
"UNIQUE (start,\"end\",\"user\")," +
"PRIMARY KEY (id));")
return err
}
func validateTables(schema string, db *sql.DB) error {
err := createLoggedUsersTable(db)
if err != nil {
return err
}
err = createAttachmentsTable(db)
if err != nil {
return err
}
err = createMonthCacheTable(db)
if err != nil {
return err
}
return nil
}