fix(sqlite): emit inline foreign keys, bare-name default schema, direct exec
SQLite can't ALTER TABLE ADD CONSTRAINT, so foreign keys are now written as inline FOREIGN KEY clauses in CREATE TABLE instead of commented-out ALTER statements. The default schema (public/main) now produces bare table names instead of a "public_" prefix; other schemas are still prefixed to avoid collisions. Also adds direct-to-file execution: the sqlite writer can now apply generated DDL straight to a .db file via Metadata["connection_string"], wired into `relspec merge --output-conn`.
This commit is contained in:
@@ -85,8 +85,11 @@ func TestWriteDatabase(t *testing.T) {
|
||||
t.Error("Expected CREATE TABLE statement")
|
||||
}
|
||||
|
||||
if !strings.Contains(output, "\"public_users\"") {
|
||||
t.Error("Expected flattened table name public_users")
|
||||
if !strings.Contains(output, "\"users\"") {
|
||||
t.Error("Expected bare table name users (default schema should not be prefixed)")
|
||||
}
|
||||
if strings.Contains(output, "\"public_users\"") {
|
||||
t.Error("Did not expect flattened table name public_users for the default public schema")
|
||||
}
|
||||
|
||||
if !strings.Contains(output, "INTEGER PRIMARY KEY AUTOINCREMENT") {
|
||||
@@ -322,13 +325,15 @@ func TestWriteSchema_MultiSchema(t *testing.T) {
|
||||
|
||||
output := buf.String()
|
||||
|
||||
// Check for flattened table names from both schemas
|
||||
// Non-default schemas are still prefixed to avoid name collisions...
|
||||
if !strings.Contains(output, "\"auth_sessions\"") {
|
||||
t.Error("Expected flattened table name auth_sessions")
|
||||
}
|
||||
|
||||
if !strings.Contains(output, "\"public_posts\"") {
|
||||
t.Error("Expected flattened table name public_posts")
|
||||
// ...but the default "public" schema is not, since it's typically the
|
||||
// only schema and bare names read better (and match e.g. DBML output).
|
||||
if !strings.Contains(output, "\"posts\"") {
|
||||
t.Error("Expected bare table name posts")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user