new schema initial commit
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-01-08 14:30:16 +11:00
parent 7ecf27f7dc
commit d1eecc5c4f
14 changed files with 631 additions and 149 deletions

View File

@@ -26,8 +26,7 @@ const createRoles string = `
CREATE TABLE IF NOT EXISTS roles (
RoleId INTEGER PRIMARY KEY ASC,
RoleName VARCHAR,
ReadOnly BOOLEAN,
Admin BOOLEAN
ReadOnly BOOLEAN
);
`
@@ -37,8 +36,8 @@ const createUsers string = `
GroupId INTEGER,
UserName VARCHAR,
Password VARCHAR,
Admin BOOLEAN DEFAULT 0,
LdapUser BOOLEAN DEFAULT 0,
LdapDN VARCHAR DEFAULT '',
FOREIGN KEY (GroupId) REFERENCES groups(GroupId)
);
`
@@ -55,7 +54,8 @@ const createGroups string = `
GroupId INTEGER PRIMARY KEY ASC,
GroupName VARCHAR,
LdapGroup BOOLEAN DEFAULT 0,
LdapDN VARCHAR DEFAULT ''
LdapDN VARCHAR DEFAULT '',
Admin BOOLEAN DEFAULT 0
);
`
@@ -213,6 +213,36 @@ func CreateTables() {
os.Exit(1)
}
// Add initial groups
rowCount, _ = CheckCount("groups")
if rowCount == 0 {
if _, err = db.Exec("INSERT INTO groups (GroupId, GroupName, Admin) VALUES(1, 'Administrators', 1);"); err != nil {
log.Printf("Error adding initial group entry id 1 : '%s'", err)
os.Exit(1)
}
if _, err = db.Exec("INSERT INTO groups (GroupId, GroupName, Admin) VALUES(2, 'Users', 0);"); err != nil {
log.Printf("Error adding initial group entry id 2 : '%s'", err)
os.Exit(1)
}
}
// Add initial permissions
rowCount, _ = CheckCount("permissions")
if rowCount == 0 {
if _, err = db.Exec("INSERT INTO permissions (RoleId, SafeId, UserId) VALUES(1, 1, 1);"); err != nil {
log.Printf("Error adding initial permissions entry userid 1 : '%s'", err)
os.Exit(1)
}
if _, err = db.Exec("INSERT INTO permissions (RoleId, SafeId, UserId) VALUES(1, 1, 2);"); err != nil {
log.Printf("Error adding initial permissions entry userid 2 : '%s'", err)
os.Exit(1)
}
if _, err = db.Exec("INSERT INTO permissions (RoleId, SafeId, UserId) VALUES(1, 1, 3);"); err != nil {
log.Printf("Error adding initial permissions entry userid 3 : '%s'", err)
os.Exit(1)
}
}
// Schema table should go last so we know if the database has a value in the schema table then everything was created properly
if _, err = db.Exec(createSchema); err != nil {
log.Printf("Error checking schema table : '%s'", err)
@@ -246,8 +276,8 @@ func CreateTables() {
GroupId INTEGER,
UserName VARCHAR,
Password VARCHAR,
LdapUser BOOLEAN DEFAULT 0,
LdapDN VARCHAR DEFAULT '',
Admin BOOLEAN DEFAULT 0,
LdapUser BOOLEAN DEFAULT 0
FOREIGN KEY (GroupId) REFERENCES groups(GroupId)
);
INSERT INTO users SELECT * FROM _users_old;