Add description_name
to clients
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (db *Database) CreateClient(ctx db.TxContext, userid models.UserID, ctype models.ClientType, fcmToken string, agentModel string, agentVersion string) (models.Client, error) {
|
||||
func (db *Database) CreateClient(ctx db.TxContext, userid models.UserID, ctype models.ClientType, fcmToken string, agentModel string, agentVersion string, descriptionName *string) (models.Client, error) {
|
||||
tx, err := ctx.GetOrCreateTransaction(db)
|
||||
if err != nil {
|
||||
return models.Client{}, err
|
||||
@@ -21,6 +21,7 @@ func (db *Database) CreateClient(ctx db.TxContext, userid models.UserID, ctype m
|
||||
TimestampCreated: time2DB(time.Now()),
|
||||
AgentModel: agentModel,
|
||||
AgentVersion: agentVersion,
|
||||
DescriptionName: descriptionName,
|
||||
}
|
||||
|
||||
_, err = sq.InsertSingle(ctx, tx, "clients", entity)
|
||||
@@ -164,3 +165,20 @@ func (db *Database) UpdateClientAgentVersion(ctx db.TxContext, clientid models.C
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *Database) UpdateClientDescriptionName(ctx db.TxContext, clientid models.ClientID, descriptionName *string) error {
|
||||
tx, err := ctx.GetOrCreateTransaction(db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = tx.Exec(ctx, "UPDATE clients SET description_name = :vvv WHERE client_id = :cid", sq.PP{
|
||||
"vvv": descriptionName,
|
||||
"cid": clientid,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -160,7 +160,7 @@ func (db *Database) Migrate(outerctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info().Int("currschema", currschema).Msg("Upgrade schema from 3 -> 4 succesfuly")
|
||||
log.Info().Int("currschema", currschema).Msg("Upgrade schema from 3 -> 4 succesfully")
|
||||
|
||||
ppReInit = true
|
||||
}
|
||||
@@ -185,6 +185,51 @@ func (db *Database) Migrate(outerctx context.Context) error {
|
||||
} else {
|
||||
log.Debug().Str("schemHash", schemHashDB).Msg("Verified Schema consistency (primary db)")
|
||||
}
|
||||
|
||||
log.Info().Int("currschema", currschema).Msg("Upgrade schema from 4 -> 5")
|
||||
|
||||
_, err = tx.Exec(tctx, schema.PrimaryMigration_4_5, sq.PP{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
currschema = 5
|
||||
|
||||
err = db.WriteMetaInt(tctx, "schema", int64(currschema))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.WriteMetaString(tctx, "schema_hash", schema.PrimarySchema[currschema].Hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Info().Int("currschema", currschema).Msg("Upgrade schema from 4 -> 5 succesfully")
|
||||
|
||||
ppReInit = true
|
||||
}
|
||||
|
||||
if currschema == 5 {
|
||||
|
||||
schemaHashMeta, err := db.ReadMetaString(tctx, "schema_hash")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
schemHashDB, err := sq.HashSqliteDatabase(tctx, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if schemHashDB != langext.Coalesce(schemaHashMeta, "") || langext.Coalesce(schemaHashMeta, "") != schema.PrimarySchema[currschema].Hash {
|
||||
log.Debug().Str("schemHashDB", schemHashDB).Msg("Schema (primary db)")
|
||||
log.Debug().Str("schemaHashMeta", langext.Coalesce(schemaHashMeta, "")).Msg("Schema (primary db)")
|
||||
log.Debug().Str("schemaHashAsset", schema.PrimarySchema[currschema].Hash).Msg("Schema (primary db)")
|
||||
return errors.New("database schema does not match (primary db)")
|
||||
} else {
|
||||
log.Debug().Str("schemHash", schemHashDB).Msg("Verified Schema consistency (primary db)")
|
||||
}
|
||||
}
|
||||
|
||||
if currschema != schema.PrimarySchemaVersion {
|
||||
|
Reference in New Issue
Block a user