diff --git a/net/schema/baseline.sql b/net/schema/baseline.sql deleted file mode 100644 index 333b4d89..00000000 --- a/net/schema/baseline.sql +++ /dev/null @@ -1,400 +0,0 @@ --- --- File generated with SQLiteStudio v3.3.3 on Sun Jan 9 20:58:42 2022 --- --- Text encoding used: UTF-8 --- -PRAGMA foreign_keys = off; -BEGIN TRANSACTION; - --- Table: account -CREATE TABLE account ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - did BLOB NOT NULL, - username VARCHAR (64) UNIQUE - NOT NULL, - password VARCHAR (256) NOT NULL, - salt VARCHAR (256) NOT NULL, - name VARCHAR (64), - description VARCHAR (4096), - location VARCHAR (64), - image BLOB, - profileRevision INTEGER (8) NOT NULL - DEFAULT (0), - contentRevision INTEGER (8) NOT NULL - DEFAULT (0), - viewRevision INTEGER (8) DEFAULT (0) - NOT NULL, - groupRevision INTEGER (8) DEFAULT (0) - NOT NULL, - labelRevision INTEGER (8) DEFAULT (0) - NOT NULL, - cardRevision INTEGER (8) DEFAULT (0) - NOT NULL, - dialogueRevision INTEGER (8) DEFAULT (0) - NOT NULL, - insightRevision INTEGER (8) DEFAULT (0) - NOT NULL -); - - --- Table: accountApp -CREATE TABLE accountApp ( - id INTEGER PRIMARY KEY - NOT NULL - UNIQUE, - accountId INTEGER REFERENCES account (id) - NOT NULL, - appId INTEGER REFERENCES app (id) - NOT NULL, - token BLOB (64) UNIQUE - NOT NULL -); - - --- Table: app -CREATE TABLE app ( - id INTEGER PRIMARY KEY - NOT NULL - UNIQUE, - name VARCHAR (64) NOT NULL, - description VARCHAR (4096), - image BLOB, - url VARCHAR (1024) -); - - --- Table: article -CREATE TABLE article ( - id INTEGER PRIMARY KEY - NOT NULL - UNIQUE, - accountId INTEGER REFERENCES account (id) - NOT NULL, - articleId VARCHAR (16), - status VARCHAR (16) NOT NULL, - subjectRevision INTEGER (8) NOT NULL, - type VARCHAR (16), - data BLOB, - created INTEGER (4) NOT NULL, - modified INTEGER (4) NOT NULL, - tagUpdated INTEGER (4) NOT NULL, - tagRevision INTEGER (8) NOT NULL, - UNIQUE ( - accountId, - articleId - ) -); - - --- Table: articleAsset -CREATE TABLE articleAsset ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - articleId INTEGER REFERENCES article (id), - assetId VARCHAR (16) NOT NULL, - originalId INTEGER REFERENCES articleAsset (id), - status VARCHAR (16) NOT NULL, - size INTEGER (8), - crc INTEGER (8), - transform VARCHAR (16), - transformData BLOB, - UNIQUE ( - articleId, - assetId - ) -); - - --- Table: articleGroup -CREATE TABLE articleGroup ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - articleId INTEGER REFERENCES article (id), - groupId INTEGER REFERENCES [group] (id) -); - - --- Table: articleLabel -CREATE TABLE articleLabel ( - id INTEGER PRIMARY KEY - NOT NULL - UNIQUE, - articleId INTEGER REFERENCES article (id), - labelId INTEGER REFERENCES label (id) -); - - --- Table: articleTag -CREATE TABLE articleTag ( - id INTEGER NOT NULL - UNIQUE - PRIMARY KEY, - articleId INTEGER REFERENCES article (id) - NOT NULL, - cardId INTEGER REFERENCES card (id) - NOT NULL, - tagId VARCHAR (16) NOT NULL, - revision INTEGER (8) NOT NULL, - type VARCHAR (16), - data BLOB, - created INTEGER (4) NOT NULL, - modified INTEGER (4) NOT NULL, - UNIQUE ( - articleId, - tagId - ) -); - - --- Table: attachCode -CREATE TABLE attachCode ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - accountId INTEGER REFERENCES account (id) - NOT NULL, - token BLOB (16) NOT NULL, - issued INTEGER (4) NOT NULL -); - - --- Table: card -CREATE TABLE card ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - accountId INTEGER REFERENCES account (id) - NOT NULL, - cardId VARCHAR (16) NOT NULL, - did BLOB NOT NULL, - username VARCHAR (64) NOT NULL, - name VARCHAR (64), - description VARCHAR (4096), - location VARCHAR (64), - revision INTEGER (64) NOT NULL, - image BLOB, - node VARCHAR (1024) NOT NULL, - status VARCHAR (16) NOT NULL, - token BLOB (64), - UNIQUE ( - accountId, - cardId - ) -); - - --- Table: cardGroup -CREATE TABLE cardGroup ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - cardId INTEGER REFERENCES card (id), - groupId INTEGER REFERENCES [group] (id) -); - - --- Table: config -CREATE TABLE config ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - [key] VARCHAR (8) UNIQUE - NOT NULL, - strValue VARCHAR (1024), - numValue INTEGER (8), - boolValue BOOLEAN -); - - --- Table: dialogue -CREATE TABLE dialogue ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - accountId INTEGER REFERENCES account (id), - dialogueId VARCHAR (16) NOT NULL, - subjectRevision INTEGER (8) NOT NULL - DEFAULT (0), - type VARCHAR (16), - data BLOB, - created INTEGER NOT NULL, - modified INTEGER NOT NULL, - active BOOLEAN NOT NULL, - memberRevision INTEGER (8) NOT NULL - DEFAULT (0), - topicUpdated INTEGER (4) NOT NULL, - topicRevision INTEGER (8) NOT NULL - DEFAULT (0), - UNIQUE ( - accountId, - dialogueId - ) -); - - --- Table: dialogueMember -CREATE TABLE dialogueMember ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - dialogueId INTEGER REFERENCES dialogue (id) - NOT NULL, - cardId INTEGER REFERENCES card (id) - NOT NULL, - added INTEGER (4) NOT NULL -); - - --- Table: group -CREATE TABLE [group] ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - groupId VARCHAR (16) NOT NULL, - accountId INTEGER REFERENCES account (id) - NOT NULL, - revision INTEGER (8) NOT NULL - DEFAULT (0), - type VARCHAR (16), - data BLOB, - created INTEGER (32) NOT NULL, - modified INTEGER (4) NOT NULL, - UNIQUE ( - groupId, - accountId - ) -); - - --- Table: insight -CREATE TABLE insight ( - id INTEGER PRIMARY KEY - NOT NULL - UNIQUE, - accountId INTEGER REFERENCES account (id) - NOT NULL, - cardId INTEGER REFERENCES card (id) - NOT NULL, - dialogueId VARCHAR (16) NOT NULL, - subjectRevision INTEGER (8) NOT NULL - DEFAULT (0), - memberRevision INTEGER (8) NOT NULL - DEFAULT (0), - topicRevision INTEGER (8) NOT NULL - DEFAULT (0), - UNIQUE ( - cardId, - dialogueId - ) -); - - --- Table: label -CREATE TABLE label ( - id INTEGER UNIQUE - PRIMARY KEY - NOT NULL, - labelId VARCHAR (16) NOT NULL, - accountId INTEGER REFERENCES account (id) - NOT NULL, - revision INTEGER (8) NOT NULL - DEFAULT (0), - type VARCHAR (16), - data BLOB, - created INTEGER (4) NOT NULL, - modified INTEGER (4) NOT NULL, - UNIQUE ( - labelId, - accountId - ) -); - - --- Table: labelGroup -CREATE TABLE labelGroup ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - labelId INTEGER REFERENCES label (id), - groupId INTEGER REFERENCES [group] (id) -); - - --- Table: topic -CREATE TABLE topic ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - accountId INTEGER REFERENCES account (id) - NOT NULL, - dialogueId INTEGER REFERENCES dialogue (id) - NOT NULL, - topicId VARCHAR (16) NOT NULL, - cardId INTEGER REFERENCES card (id), - status VARCHAR (16) NOT NULL, - subjectRevision INTEGER (8) NOT NULL - DEFAULT (0), - type VARCHAR (16), - data BLOB, - created INTEGER (4), - modified INTEGER (4), - tagUpdated INTEGER (4), - tagRevision INTEGER (8) NOT NULL - DEFAULT (0), - UNIQUE ( - accountId, - topicId - ) -); - - --- Table: topicAsset -CREATE TABLE topicAsset ( - id INTEGER PRIMARY KEY - UNIQUE - NOT NULL, - topicId INTEGER REFERENCES topic (id) - NOT NULL, - assetId VARCHAR (16) NOT NULL, - originalId INTEGER REFERENCES topicAsset (id) - NOT NULL, - status VARCHAR (16), - size INTEGER (8), - crc INTEGER (4), - transform VARCHAR (16), - transformData BLOB, - UNIQUE ( - topicId, - assetId - ) -); - - --- Table: topicTag -CREATE TABLE topicTag ( - id PRIMARY KEY - UNIQUE - NOT NULL, - topicId INTEGER REFERENCES topic (id) - NOT NULL, - cardId INTEGER REFERENCES card (id), - tagId VARCHAR (16) NOT NULL, - revision INTEGER (8) NOT NULL - DEFAULT (0), - type VARCHAR (16), - data BLOB, - created INTEGER (4) NOT NULL, - modified INTEGER (4) NOT NULL, - UNIQUE ( - topicId, - tagId - ) -); - - -COMMIT TRANSACTION; -PRAGMA foreign_keys = on; diff --git a/net/schema/cmd b/net/schema/cmd deleted file mode 100644 index 09d07740..00000000 --- a/net/schema/cmd +++ /dev/null @@ -1 +0,0 @@ -sqlite3 databag.db "VACUUM;" diff --git a/net/server/internal/store/db_schema.go b/net/server/internal/store/db_schema.go index c4f501cb..052255f0 100644 --- a/net/server/internal/store/db_schema.go +++ b/net/server/internal/store/db_schema.go @@ -3,6 +3,7 @@ package store import "gorm.io/gorm" func AutoMigrate(db *gorm.DB) { + db.AutoMigrate(&Config{}); db.AutoMigrate(&App{}); db.AutoMigrate(&Account{}); db.AutoMigrate(&AccountToken{}); @@ -16,168 +17,264 @@ func AutoMigrate(db *gorm.DB) { db.AutoMigrate(&ArticleTag{}); db.AutoMigrate(&ArticleGroup{}); db.AutoMigrate(&ArticleLabel{}); + db.AutoMigrate(&Dialogue{}); + db.AutoMigrate(&DialogueMember{}); + db.AutoMigrate(&Insight{}); + db.AutoMigrate(&Topic{}); + db.AutoMigrate(&TopicAsset{}); + db.AutoMigrate(&TopicTag{}); +} + +type Config struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + ConfigId string `gorm:"not null;uniqueIndex"` + StrValue string + NumValue int64 + BoolValue bool } type AccountToken struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - AccountID uint `gorm:"index"` - TokenType string `gorm:"not null; ` - Token string `gorm:"not null;uniqueIndex"` - Created int64 `gorm:"autoCreateTime"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + AccountID uint `gorm:"index"` + TokenType string `gorm:"not null; ` + Token string `gorm:"not null;uniqueIndex"` + Created int64 `gorm:"autoCreateTime"` Account Account } type Account struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - Did string `gorm:"not null"` - Username string `gorm:"not null;uniqueIndex"` - Password string `gorm:"not null"` - Salt string `gorm:"not null"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + Did string `gorm:"not null"` + Username string `gorm:"not null;uniqueIndex"` + Password string `gorm:"not null"` + Salt string `gorm:"not null"` Name string Description string Location string Image string - profileRevision uint64 `gorm:"not null"` - contentRevision uint64 `gorm:"not null"` - viewRevision uint64 `gorm:"not null"` - groupRevision uint64 `gorm:"not null"` - labelRevision uint64 `gorm:"not null"` - cardRevision uint64 `gorm:"not null"` - dialogueRevision uint64 `gorm:"not null"` - insightRevision uint64 `gorm:"not null"` - Created int64 `gorm:"autoCreateTime"` + profileRevision uint64 `gorm:"not null"` + contentRevision uint64 `gorm:"not null"` + viewRevision uint64 `gorm:"not null"` + groupRevision uint64 `gorm:"not null"` + labelRevision uint64 `gorm:"not null"` + cardRevision uint64 `gorm:"not null"` + dialogueRevision uint64 `gorm:"not null"` + insightRevision uint64 `gorm:"not null"` + Created int64 `gorm:"autoCreateTime"` Apps []App } type App struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - AccountID uint `gorm:"index"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + AccountID uint `gorm:"index"` Name string Description string Image string Url string - Token string `gorm:"not null;index"` - Created int64 `gorm:"autoCreateTime"` + Token string `gorm:"not null;index"` + Created int64 `gorm:"autoCreateTime"` Account Account } type Group struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - GroupId string `gorm:"not null;index:group,unqiue"` - AccountID uint `gorm:"not null;index:group,unique"` - Revision int64 `gorm:"not null"` - DataType string `gorm:"index"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + GroupId string `gorm:"not null;index:group,unqiue"` + AccountID uint `gorm:"not null;index:group,unique"` + Revision int64 `gorm:"not null"` + DataType string `gorm:"index"` Data string - Created int64 `gorm:"autoCreateTime"` - Updated int64 `gorm:"autoUpdateTime"` + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + Account Account } type Label struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - LabelId string `gorm:"not null;index:label,unique"` - AccountID uint `gorm:"not null;index:label,unique"` - Revision int64 `gorm:"not null"` - DataType string `gorm:"index"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + LabelId string `gorm:"not null;index:label,unique"` + AccountID uint `gorm:"not null;index:label,unique"` + Revision int64 `gorm:"not null"` + DataType string `gorm:"index"` Data string - Created int64 `gorm:"autoCreateTime"` - Updated int64 `gorm:"autoUpdateTime"` + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + Account Account } type Card struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - CardId string `gorm:"not null;index:card,unique"` - AccountID uint `gorm:"not null;index:card,unique"` - DID string `gorm:"not null"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + CardId string `gorm:"not null;index:card,unique"` + AccountID uint `gorm:"not null;index:card,unique"` + DID string `gorm:"not null"` Username string Name string Description string Location string - Revision uint64 `gorm:"not null"` + Revision uint64 `gorm:"not null"` Image string - Node string `gorm:"not null"` - Status string `gorm:"not null"` + Node string `gorm:"not null"` + Status string `gorm:"not null"` Token string - Created int64 `gorm:"autoCreateTime"` - Updated int64 `gorm:"autoUpdateTime"` - Groups []Group `gorm:"many2many:card_groups;"` + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + Account Account + Groups []Group `gorm:"many2many:card_groups;"` } type CardGroup struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - CardID uint `gorm:"not null;index:cardgroup,unique"` - GroupID uint `gorm:"not null;index:cardgroup,unique"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + CardID uint `gorm:"not null;index:cardgroup,unique"` + GroupID uint `gorm:"not null;index:cardgroup,unique"` Card Card Group Group } type LabelGroup struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - LabelID uint `gorm:"not null;index:labelgroup,unique"` - GroupID uint `gorm:"not null;index:labelgroup,unique"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + LabelID uint `gorm:"not null;index:labelgroup,unique"` + GroupID uint `gorm:"not null;index:labelgroup,unique"` Label Label Group Group } type Article struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - ArticleId string `gorm:"not null;index:article,unique"` - AccountID uint `gorm:"not null;index:article,unique"` - Revision int64 `gorm:"not null"` - DataType string `gorm:"index"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + ArticleId string `gorm:"not null;index:article,unique"` + AccountID uint `gorm:"not null;index:article,unique"` + Revision int64 `gorm:"not null"` + DataType string `gorm:"index"` Data string - Status string `gorm:"not null;index"` - Created int64 `gorm:"autoCreateTime"` - Updated int64 `gorm:"autoUpdateTime"` - TagUpdated int64 `gorm:"not null"` - TagRevision uint64 `gorm:"not null"` - ArticleTags []ArticleTag + Status string `gorm:"not null;index"` + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + TagUpdated int64 `gorm:"not null"` + TagRevision uint64 `gorm:"not null"` + Account Account } type ArticleAsset struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - AssetId string `gorm:"not null;index:articleasset,unique"` - ArticleID uint `gorm:"not null;index:articleasset,unique"` - Status string `gorm:"not null;index"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + AssetId string `gorm:"not null;index:articleasset,unique"` + ArticleID uint `gorm:"not null;index:articleasset,unique"` + Status string `gorm:"not null;index"` Size uint64 Crc uint32 Transform string TransformId string TransformData string - Created int64 `gorm:"autoCreateTime"` + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` Article Article } type ArticleTag struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - TagId string `gorm:"not null;index:articletag,unique"` - ArticleID uint `gorm:"not null;index:articletag,unique"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + TagId string `gorm:"not null;index:articletag,unique"` + ArticleID uint `gorm:"not null;index:articletag,unique"` CardID uint - Revision int64 `gorm:"not null"` - DataType string `gorm:"index"` + Revision int64 `gorm:"not null"` + DataType string `gorm:"index"` Data string - Created int64 `gorm:"autoCreateTime"` - Updated int64 `gorm:"autoUpdateTime"` + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` Article Article Card Card } type ArticleGroup struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - ArticleID uint `gorm:"not null;index"` - GroupID uint `gorm:"not null;index"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + ArticleID uint `gorm:"not null;index"` + GroupID uint `gorm:"not null;index"` Article Article Group Group } type ArticleLabel struct { - ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - ArticleID uint `gorm:"not null;index"` - LabelID uint `gorm:"not null;index"` + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + ArticleID uint `gorm:"not null;index"` + LabelID uint `gorm:"not null;index"` Article Article Label Label } - - +type Dialogue struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + DialogueId string `gorm:"not null;index:dialogue,unique"` + AccountID uint `gorm:"not null;index:dialogue,unique"` + Revision int64 `gorm:"not null"` + DataType string `gorm:"index"` + Data string + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + Active bool `gorm:"not null"` + MemberRevision uint64 `gorm:"not null"` + TopicUpdated int64 + TopicRevision uint64 `gorm:"not null"` + Account Account + Cards []Card `gorm:"many2many:dialogue_member"` +} + +type DialogueMember struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + DialogueID uint `gorm:"not null;index` + CardID uint `gorm:"not null;index` + Created int64 `gorm:"autoCreateTime"` + Card Card +} + +type Insight struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + InsightId string `gorm:"not null;index:insight,unique"` + CardID uint `gorm:"not null;index:insight,unique"` + dialogueRevision uint64 `gorm:"not null"` + memberRevision uint64 `gorm:"not null"` + topicRevision uint64 `gorm:"not null"` + Card Card +} + +type Topic struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + TopicId string `gorm:"not null;index:topic,unique"` + AccountID uint `gorm:"not null;index:topic,unique"` + CardID uint + Revision int64 `gorm:"not null"` + DataType string `gorm:"index"` + Data string + Status string `gorm:"not null;index"` + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + TagUpdated int64 `gorm:"not null"` + TagRevision uint64 `gorm:"not null"` + Account Account + Card Card +} + +type TopicAsset struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + AssetId string `gorm:"not null;index:topicasset,unique"` + TopicID uint `gorm:"not null;index:topicasset,unique"` + Status string `gorm:"not null;index"` + Size uint64 + Crc uint32 + Transform string + TransformId string + TransformData string + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + Topic Topic +} + +type TopicTag struct { + ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` + TagId string `gorm:"not null;index:topictag,unique"` + TopicID uint `gorm:"not null;index:topictag,unique"` + CardID uint + Revision int64 `gorm:"not null"` + DataType string `gorm:"index"` + Data string + Created int64 `gorm:"autoCreateTime"` + Updated int64 `gorm:"autoUpdateTime"` + Topic Topic + Card Card +}