2022-04-18 21:10:15 +00:00
BEGIN TRANSACTION ;
2022-09-16 22:49:07 +00:00
CREATE TABLE IF NOT EXISTS " params " (
2022-11-07 18:40:40 +00:00
" name " TEXT NOT NULL UNIQUE ,
2022-11-30 22:12:42 +00:00
" value " TEXT NOT NULL ,
PRIMARY KEY ( " name " )
) ;
2023-03-09 00:35:30 +00:00
INSERT INTO " params " ( " name " , " value " ) VALUES ( ' instance_bucket_tokens ' , ' 0 ' ) ;
INSERT INTO " params " ( " name " , " value " ) VALUES ( ' instance_bucket_last_update ' , ' 0 ' ) ;
INSERT INTO " params " ( " name " , " value " ) VALUES ( ' secret_key ' , ' 0 ' ) ;
INSERT INTO " params " ( " name " , " value " ) VALUES ( ' secret_key_last_change ' , ' 0 ' ) ;
INSERT INTO " params " ( " name " , " value " ) VALUES ( ' username_salt ' , ' 00000000000000000000000000000000 ' ) ; -- Should be unique and secret ; generate one using `openssl rand -hex 16` ; can't be changed without breaking current accounts login
2022-11-30 22:12:42 +00:00
CREATE TABLE IF NOT EXISTS " users " (
2023-03-25 15:26:05 +00:00
" id " TEXT NOT NULL UNIQUE CHECK ( LENGTH ( id ) = 64 ) ,
2022-11-30 22:12:42 +00:00
" username " TEXT NOT NULL UNIQUE ,
" password " TEXT NOT NULL ,
" registration_date " TEXT NOT NULL ,
" bucket_tokens " INTEGER NOT NULL ,
" bucket_last_update " INTEGER NOT NULL ,
" type " TEXT NOT NULL ,
2023-03-09 00:35:30 +00:00
" services " TEXT NOT NULL ,
2022-11-30 22:12:42 +00:00
PRIMARY KEY ( " id " )
2022-09-16 22:49:07 +00:00
) ;
2022-12-10 17:19:37 +00:00
CREATE TABLE IF NOT EXISTS " approval-keys " (
" key " TEXT NOT NULL UNIQUE ,
PRIMARY KEY ( " key " )
) ;
2022-04-18 21:10:15 +00:00
CREATE TABLE IF NOT EXISTS " registry " (
2022-11-07 18:40:40 +00:00
" domain " TEXT NOT NULL UNIQUE ,
" username " TEXT NOT NULL ,
2023-03-25 15:26:05 +00:00
" creation " TEXT NOT NULL ,
2022-11-30 22:12:42 +00:00
PRIMARY KEY ( " domain " ) ,
FOREIGN KEY ( " username " ) REFERENCES " users " ( " id " )
2022-04-18 21:10:15 +00:00
) ;
2023-03-25 15:26:05 +00:00
CREATE TABLE IF NOT EXISTS " registry-history " (
" domain " TEXT NOT NULL ,
" creation " TEXT NOT NULL ,
" expiration " TEXT NOT NULL
) ;
2022-04-18 21:10:15 +00:00
CREATE TABLE IF NOT EXISTS " zones " (
2022-11-07 18:40:40 +00:00
" zone " TEXT NOT NULL UNIQUE ,
" username " TEXT NOT NULL ,
2022-11-30 22:12:42 +00:00
PRIMARY KEY ( " zone " ) ,
FOREIGN KEY ( " username " ) REFERENCES " users " ( " id " )
2022-04-18 21:10:15 +00:00
) ;
2023-06-24 14:54:36 +00:00
CREATE TABLE IF NOT EXISTS " ns-syncs " (
" username " TEXT NOT NULL ,
" source " TEXT NOT NULL ,
" destination " TEXT NOT NULL UNIQUE ,
FOREIGN KEY ( " username " ) REFERENCES " users " ( " id " ) ,
FOREIGN KEY ( " destination " ) REFERENCES " zones " ( " zone " )
) ;
2022-04-18 21:10:15 +00:00
CREATE TABLE IF NOT EXISTS " sites " (
2022-11-07 18:40:40 +00:00
" username " TEXT NOT NULL ,
" site_dir " TEXT NOT NULL ,
2022-12-22 00:44:57 +00:00
" address " TEXT NOT NULL ,
" type " TEXT NOT NULL ,
2022-11-07 18:40:40 +00:00
" creation_date " TEXT NOT NULL ,
2022-12-22 00:44:57 +00:00
UNIQUE ( " address " , " type " ) ,
UNIQUE ( " username " , " site_dir " , " type " ) ,
PRIMARY KEY ( " address " , " type " ) ,
2022-11-30 22:12:42 +00:00
FOREIGN KEY ( " username " ) REFERENCES " users " ( " id " )
2022-04-18 21:10:15 +00:00
) ;
2023-06-15 01:35:42 +00:00
CREATE TABLE IF NOT EXISTS " ssh-keys " (
" key " TEXT NOT NULL ,
" username " TEXT NOT NULL ,
" directory " TEXT NOT NULL ,
UNIQUE ( " key " , " username " , " directory " ) ,
FOREIGN KEY ( " username " ) REFERENCES " users " ( " id " )
) ;
2022-04-18 21:10:15 +00:00
COMMIT ;