feat: PostgreSQL as the panel's database, chosen in Настройки, the SQLite data copied over on its first start; tested on a real PostgreSQL

This commit is contained in:
redtea committed 2026-10-16 09:39:06 +03:00
1 parent 055020c3bb
commit 187dc2ae97
3 files changed
+106 -6

No files matched your search

+12 -6
View File
@@ -167,16 +167,22 @@ func copyDB(src, dst *DB) error {
return err
}
}
if err := tx.Commit(); err != nil {
return err
}
// The id counters past the copied ids, where a table has one.
for _, t := range copyTables {
var seq sql.NullString
_ = tx.QueryRow(`SELECT pg_get_serial_sequence($1, 'id')`, t).Scan(&seq)
if seq.Valid {
if _, err := tx.Exec(`SELECT setval($1, COALESCE((SELECT MAX(id) FROM `+t+`), 0) + 1, false)`, seq.String); err != nil {
return err
}
err := dst.sql.DB.QueryRow(`SELECT pg_get_serial_sequence($1, column_name) FROM information_schema.columns
WHERE table_name = $1 AND column_name = 'id' AND column_default LIKE 'nextval%'`, t).Scan(&seq)
if err != nil || !seq.Valid {
continue
}
if _, err := dst.sql.DB.Exec(`SELECT setval($1, COALESCE((SELECT MAX(id) FROM `+t+`), 0) + 1, false)`, seq.String); err != nil {
return err
}
}
return tx.Commit()
return nil
}
// Backend tells which database is in use and which is chosen for the next