2023-12-27 22:23:10 +01:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
)
|
|
|
|
|
|
|
|
var db *sql.DB
|
|
|
|
|
|
|
|
func InitDB(driver string, connStr string) error {
|
|
|
|
var err error
|
|
|
|
db, err = sql.Open(driver, connStr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = db.Exec(`
|
|
|
|
CREATE TABLE IF NOT EXISTS projects (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
title TEXT
|
|
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS lists (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
project_id INTEGER,
|
|
|
|
title TEXT,
|
|
|
|
color TEXT,
|
|
|
|
FOREIGN KEY(project_id) REFERENCES projects(id)
|
|
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS cards (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2023-12-29 01:49:09 +01:00
|
|
|
project_id INTEGER,
|
2023-12-27 22:23:10 +01:00
|
|
|
title TEXT,
|
|
|
|
content TEXT,
|
2023-12-29 01:49:09 +01:00
|
|
|
FOREIGN KEY(project_id) REFERENCES projects(id)
|
2023-12-29 03:08:08 +01:00
|
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS tags (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
project_id INTEGER,
|
|
|
|
title TEXT,
|
|
|
|
type int,
|
|
|
|
FOREIGN KEY(project_id) REFERENCES projects(id)
|
|
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS cardtags (
|
|
|
|
card_id INTEGER,
|
|
|
|
tag_id INTEGER,
|
2023-12-31 04:35:52 +01:00
|
|
|
option_id TEXT,
|
2023-12-29 03:08:08 +01:00
|
|
|
value TEXT,
|
2023-12-30 16:03:44 +01:00
|
|
|
PRIMARY KEY(card_id, tag_id),
|
2023-12-29 03:08:08 +01:00
|
|
|
FOREIGN KEY(card_id) REFERENCES cards(id)
|
|
|
|
FOREIGN KEY(tag_id) REFERENCES tags(id)
|
2023-12-31 04:35:52 +01:00
|
|
|
FOREIGN KEY(option_id) REFERENCES tagsoptions(id)
|
2023-12-31 01:38:17 +01:00
|
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS tagsoptions (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
tag_id INTEGER,
|
|
|
|
value TEXT,
|
|
|
|
FOREIGN KEY(tag_id) REFERENCES tags(id)
|
2023-12-27 22:23:10 +01:00
|
|
|
);
|
2023-12-31 05:53:46 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS views (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
project_id INTEGER,
|
|
|
|
primary_tag_id INTEGER,
|
|
|
|
secondary_tag_id INTEGER,
|
|
|
|
title TEXT,
|
|
|
|
FOREIGN KEY(project_id) REFERENCES projects(id),
|
|
|
|
FOREIGN KEY(primary_tag_id) REFERENCES tags(id),
|
|
|
|
FOREIGN KEY(secondary_tag_id) REFERENCES tags(id)
|
|
|
|
);
|
2023-12-27 22:23:10 +01:00
|
|
|
`)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|