Fix missing field in clients struct and non-partial fcmtoken index (also streamline db migrations)
All checks were successful
Build Docker and Deploy / Build Docker Container (push) Successful in 1m52s
Build Docker and Deploy / Deploy to Server (push) Successful in 7s

This commit is contained in:
2024-09-17 22:25:09 +02:00
parent 4c7632a144
commit 9d35916280
9 changed files with 309 additions and 43 deletions

View File

@@ -121,8 +121,8 @@ func (db *Database) Migrate(outerctx context.Context) error {
if currschema == 0 {
log.Info().Msgf("Migrate database (initialize) [%s] %d -> %d", db.name, currschema, db.schemaVersion)
schemastr := db.schema[1].SQL
schemahash := db.schema[1].Hash
schemastr := db.schema[db.schemaVersion].SQL
schemahash := db.schema[db.schemaVersion].Hash
_, err = tx.Exec(tctx, schemastr, sq.PP{})
if err != nil {
@@ -177,7 +177,15 @@ func (db *Database) Migrate(outerctx context.Context) error {
//goland:noinspection SqlConstantCondition,SqlWithoutWhere
func (db *Database) migrateSingle(tctx *simplectx.SimpleContext, tx sq.Tx, schemaFrom int, schemaTo int) error {
// ADD MIGRATIONS HERE ...
if schemaFrom == schemaTo-1 {
migSQL := db.schema[schemaTo].MigScript
if migSQL == "" {
return exerr.New(exerr.TypeInternal, fmt.Sprintf("missing %s migration from %d to %d", db.name, schemaFrom, schemaTo)).Build()
}
return db.migrateBySQL(tctx, tx, migSQL, schemaFrom, schemaTo, db.schema[schemaTo].Hash, nil)
}
return exerr.New(exerr.TypeInternal, fmt.Sprintf("missing %s migration from %d to %d", db.name, schemaFrom, schemaTo)).Build()
}

View File

@@ -121,8 +121,8 @@ func (db *Database) Migrate(outerctx context.Context) error {
if currschema == 0 {
log.Info().Msgf("Migrate database (initialize) [%s] %d -> %d", db.name, currschema, db.schemaVersion)
schemastr := db.schema[1].SQL
schemahash := db.schema[1].Hash
schemastr := db.schema[db.schemaVersion].SQL
schemahash := db.schema[db.schemaVersion].Hash
_, err = tx.Exec(tctx, schemastr, sq.PP{})
if err != nil {
@@ -177,20 +177,14 @@ func (db *Database) Migrate(outerctx context.Context) error {
//goland:noinspection SqlConstantCondition,SqlWithoutWhere
func (db *Database) migrateSingle(tctx *simplectx.SimpleContext, tx sq.Tx, schemaFrom int, schemaTo int) error {
if schemaFrom == 3 && schemaTo == 4 {
return db.migrateBySQL(tctx, tx, schema.PrimaryMigration_3_4, schemaFrom, schemaTo, db.schema[schemaTo].Hash, nil)
}
if schemaFrom == schemaTo-1 {
if schemaFrom == 4 && schemaTo == 5 {
return db.migrateBySQL(tctx, tx, schema.PrimaryMigration_4_5, schemaFrom, schemaTo, db.schema[schemaTo].Hash, nil)
}
migSQL := db.schema[schemaTo].MigScript
if migSQL == "" {
return exerr.New(exerr.TypeInternal, fmt.Sprintf("missing %s migration from %d to %d", db.name, schemaFrom, schemaTo)).Build()
}
if schemaFrom == 5 && schemaTo == 6 {
return db.migrateBySQL(tctx, tx, schema.PrimaryMigration_5_6, schemaFrom, schemaTo, db.schema[schemaTo].Hash, nil)
}
if schemaFrom == 6 && schemaTo == 7 {
return db.migrateBySQL(tctx, tx, schema.PrimaryMigration_6_7, schemaFrom, schemaTo, db.schema[schemaTo].Hash, nil)
return db.migrateBySQL(tctx, tx, migSQL, schemaFrom, schemaTo, db.schema[schemaTo].Hash, nil)
}
return exerr.New(exerr.TypeInternal, fmt.Sprintf("missing %s migration from %d to %d", db.name, schemaFrom, schemaTo)).Build()

View File

@@ -121,8 +121,8 @@ func (db *Database) Migrate(outerctx context.Context) error {
if currschema == 0 {
log.Info().Msgf("Migrate database (initialize) [%s] %d -> %d", db.name, currschema, db.schemaVersion)
schemastr := db.schema[1].SQL
schemahash := db.schema[1].Hash
schemastr := db.schema[db.schemaVersion].SQL
schemahash := db.schema[db.schemaVersion].Hash
_, err = tx.Exec(tctx, schemastr, sq.PP{})
if err != nil {
@@ -177,7 +177,15 @@ func (db *Database) Migrate(outerctx context.Context) error {
//goland:noinspection SqlConstantCondition,SqlWithoutWhere
func (db *Database) migrateSingle(tctx *simplectx.SimpleContext, tx sq.Tx, schemaFrom int, schemaTo int) error {
// ADD MIGRATIONS HERE ...
if schemaFrom == schemaTo-1 {
migSQL := db.schema[schemaTo].MigScript
if migSQL == "" {
return exerr.New(exerr.TypeInternal, fmt.Sprintf("missing %s migration from %d to %d", db.name, schemaFrom, schemaTo)).Build()
}
return db.migrateBySQL(tctx, tx, migSQL, schemaFrom, schemaTo, db.schema[schemaTo].Hash, nil)
}
return exerr.New(exerr.TypeInternal, fmt.Sprintf("missing %s migration from %d to %d", db.name, schemaFrom, schemaTo)).Build()
}