Setup and migration UI refactor (#1190)

* Make config instance-based
* Remove config dependency in paths
* Refactor config init
* Allow startup without database
* Get system status at UI initialise
* Add setup wizard
* Cache and Metadata optional. Database mandatory
* Handle metadata not set during full import/export
* Add links
* Remove config check middleware
* Stash not mandatory
* Panic on missing mandatory config fields
* Redirect setup to main page if setup not required
* Add migration UI
* Remove unused stuff
* Move UI initialisation into App
* Don't create metadata paths on RefreshConfig
* Add folder selector for generated in setup
* Env variable to set and create config file.
Make docker images use a fixed config file.
* Set config file during setup
This commit is contained in:
WithoutPants
2021-04-12 09:31:33 +10:00
committed by GitHub
parent c38660d209
commit f6ffda7504
52 changed files with 1467 additions and 682 deletions

View File

@@ -26,8 +26,27 @@ var dbPath string
var appSchemaVersion uint = 20
var databaseSchemaVersion uint
var (
// ErrMigrationNeeded indicates that a database migration is needed
// before the database can be initialized
ErrMigrationNeeded = errors.New("database migration required")
// ErrDatabaseNotInitialized indicates that the database is not
// initialized, usually due to an incomplete configuration.
ErrDatabaseNotInitialized = errors.New("database not initialized")
)
const sqlite3Driver = "sqlite3ex"
// Ready returns an error if the database is not ready to begin transactions.
func Ready() error {
if DB == nil {
return ErrDatabaseNotInitialized
}
return nil
}
func init() {
// register custom driver with regexp function
registerCustomDriver()
@@ -37,20 +56,20 @@ func init() {
// performs a full migration to the latest schema version. Otherwise, any
// necessary migrations must be run separately using RunMigrations.
// Returns true if the database is new.
func Initialize(databasePath string) bool {
func Initialize(databasePath string) error {
dbPath = databasePath
if err := getDatabaseSchemaVersion(); err != nil {
panic(err)
return fmt.Errorf("error getting database schema version: %s", err.Error())
}
if databaseSchemaVersion == 0 {
// new database, just run the migrations
if err := RunMigrations(); err != nil {
panic(err)
return fmt.Errorf("error running initial schema migrations: %s", err.Error())
}
// RunMigrations calls Initialise. Just return
return true
return nil
} else {
if databaseSchemaVersion > appSchemaVersion {
panic(fmt.Sprintf("Database schema version %d is incompatible with required schema version %d", databaseSchemaVersion, appSchemaVersion))
@@ -59,7 +78,7 @@ func Initialize(databasePath string) bool {
// if migration is needed, then don't open the connection
if NeedsMigration() {
logger.Warnf("Database schema version %d does not match required schema version %d.", databaseSchemaVersion, appSchemaVersion)
return false
return nil
}
}
@@ -67,7 +86,7 @@ func Initialize(databasePath string) bool {
DB = open(databasePath, disableForeignKeys)
WriteMu = &sync.Mutex{}
return false
return nil
}
func open(databasePath string, disableForeignKeys bool) *sqlx.DB {
@@ -150,6 +169,10 @@ func AppSchemaVersion() uint {
return appSchemaVersion
}
func DatabasePath() string {
return dbPath
}
func DatabaseBackupPath() string {
return fmt.Sprintf("%s.%d.%s", dbPath, databaseSchemaVersion, time.Now().Format("20060102_150405"))
}