diff --git a/internal/entity/deprecated.go b/internal/entity/deprecated.go new file mode 100644 index 000000000..7fc7017af --- /dev/null +++ b/internal/entity/deprecated.go @@ -0,0 +1,38 @@ +package entity + +// Deprecated represents a list of deprecated database tables; +type Deprecated []string + +// Drop drops all deprecated tables. +func (list Deprecated) Drop() { + for _, tableName := range list { + if err := UnscopedDb().DropTableIfExists(tableName).Error; err != nil { + log.Debugf("drop %s: %s", tableName, err) + } + } +} + +// DeprecatedTables lists deprecated development database tables, so that they can be removed. +var DeprecatedTables = Deprecated{ + "subjects_dev1", + "subjects_dev2", + "subjects_dev3", + "subjects_dev4", + "subjects_dev5", + "subjects_dev6", + "subjects_dev7", + "markers_dev1", + "markers_dev2", + "markers_dev3", + "markers_dev4", + "markers_dev5", + "markers_dev6", + "markers_dev7", + "faces_dev1", + "faces_dev2", + "faces_dev3", + "faces_dev4", + "faces_dev5", + "faces_dev6", + "faces_dev7", +} diff --git a/internal/entity/entity.go b/internal/entity/entity.go index 3607e51a1..6d4e14349 100644 --- a/internal/entity/entity.go +++ b/internal/entity/entity.go @@ -135,6 +135,7 @@ func CreateDefaultFixtures() { // MigrateDb creates all tables and inserts default entities as needed. func MigrateDb() { + DeprecatedTables.Drop() Entities.Migrate() Entities.WaitForMigration() diff --git a/internal/entity/face.go b/internal/entity/face.go index 7d35336f8..faf2559f3 100644 --- a/internal/entity/face.go +++ b/internal/entity/face.go @@ -38,7 +38,7 @@ var Faceless = []string{""} // TableName returns the entity database table name. func (Face) TableName() string { - return "faces_dev7" + return "faces_dev8" } // NewFace returns a new face. diff --git a/internal/entity/marker.go b/internal/entity/marker.go index b7f70b091..00d4a8d99 100644 --- a/internal/entity/marker.go +++ b/internal/entity/marker.go @@ -57,7 +57,7 @@ type Marker struct { // TableName returns the entity database table name. func (Marker) TableName() string { - return "markers_dev7" + return "markers_dev8" } // BeforeCreate creates a random UID if needed before inserting a new row to the database. diff --git a/internal/entity/subject.go b/internal/entity/subject.go index cf891721b..18c2bdac0 100644 --- a/internal/entity/subject.go +++ b/internal/entity/subject.go @@ -42,7 +42,7 @@ type Subject struct { // TableName returns the entity database table name. func (Subject) TableName() string { - return "subjects_dev7" + return "subjects_dev8" } // BeforeCreate creates a random UID if needed before inserting a new row to the database.