@@ -138,6 +138,51 @@ func TestOpenRecordsCurrentSchemaVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchemaIndexStatementsAreDialectAware(t *testing.T) {
|
||||
mysql := dialectFor("mysql")
|
||||
sqlite := dialectFor("sqlite")
|
||||
for _, statement := range schemaStatements(mysql) {
|
||||
if strings.Contains(strings.ToUpper(statement), "CREATE INDEX IF NOT EXISTS") {
|
||||
t.Fatalf("mysql schema statement contains unsupported index syntax: %s", statement)
|
||||
}
|
||||
}
|
||||
|
||||
index := schemaIndexes()[0]
|
||||
mysqlStatement := createIndexStatement(mysql, index)
|
||||
if strings.Contains(strings.ToUpper(mysqlStatement), "IF NOT EXISTS") {
|
||||
t.Fatalf("mysql index statement contains unsupported syntax: %s", mysqlStatement)
|
||||
}
|
||||
if !strings.Contains(createIndexStatement(sqlite, index), "IF NOT EXISTS") {
|
||||
t.Fatalf("sqlite index statement should remain idempotent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMigrateCreatesSQLiteIndexesIdempotently(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
conn, err := sql.Open("sqlite", filepath.Join(root, "indexes.sqlite"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
store := &Store{}
|
||||
d := dialectFor("sqlite")
|
||||
if err := store.migrate(conn, d); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.migrate(conn, d); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var name string
|
||||
if err := conn.QueryRow(`SELECT name FROM sqlite_master WHERE type = 'index' AND name = ?`, "idx_feedback_tickets_activity").Scan(&name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if name != "idx_feedback_tickets_activity" {
|
||||
t.Fatalf("unexpected index name %q", name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChangeAdminPasswordPersistsWhenRemoteSyncFails(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
path := filepath.Join(root, "unified.sqlite")
|
||||
|
||||
Reference in New Issue
Block a user