focus/backend/db/main.go

56 lines
1.2 KiB
Go
Raw Normal View History

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,
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-27 22:23:10 +01:00
);
`)
if err != nil {
return err
}
return nil
}