mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
filer/postgres_flat: name a missing filemeta table instead of a foreign layout
With createTable = false and no filemeta table, the layout check said the table had no path column and blamed a postgres2 layout. Report the missing table and the key-value table that also has to be created. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6df73344ca
commit
2fddcae20e
2 files changed
+18
-5
No files matched your search
@@ -85,14 +85,18 @@ func (store *PostgresFlatStore) initialize(createTable, upsertQuery string, enab
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkFlatLayout refuses a filemeta table of the postgres or postgres2 layout.
|
||||
// checkFlatLayout refuses a missing filemeta table, which only a createTable
|
||||
// of false leaves, and one of the postgres or postgres2 layout.
|
||||
func checkFlatLayout(ctx context.Context, db *sql.DB) error {
|
||||
var found bool
|
||||
if err := db.QueryRowContext(ctx, `SELECT EXISTS (SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = current_schema() AND table_name = $1 AND column_name = 'path')`, abstract_sql.DEFAULT_TABLE).Scan(&found); err != nil {
|
||||
var columns, pathColumns int
|
||||
if err := db.QueryRowContext(ctx, `SELECT count(*), count(*) FILTER (WHERE column_name = 'path') FROM information_schema.columns
|
||||
WHERE table_schema = current_schema() AND table_name = $1`, abstract_sql.DEFAULT_TABLE).Scan(&columns, &pathColumns); err != nil {
|
||||
return fmt.Errorf("check table %s: %v", abstract_sql.DEFAULT_TABLE, err)
|
||||
}
|
||||
if !found {
|
||||
if columns == 0 {
|
||||
return fmt.Errorf("table %s does not exist: with createTable = false, create it and %s beforehand", abstract_sql.DEFAULT_TABLE, kvTable)
|
||||
}
|
||||
if pathColumns == 0 {
|
||||
return fmt.Errorf("table %s has no path column: postgres_flat needs a database or schema of its own, apart from the postgres and postgres2 stores", abstract_sql.DEFAULT_TABLE)
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -72,3 +72,12 @@ func TestRefusesAnotherLayout(t *testing.T) {
|
||||
}
|
||||
store.Shutdown()
|
||||
}
|
||||
|
||||
func TestRefusesAMissingTableWithoutDDL(t *testing.T) {
|
||||
store := &PostgresFlatStore{}
|
||||
err := store.initialize("false", "", true, postgres.Connection{DSNOptions: store_test.NewPostgresTestDatabase(t)})
|
||||
if err == nil || !strings.Contains(err.Error(), "does not exist") {
|
||||
t.Fatalf("initialize without DDL on an empty schema: %v", err)
|
||||
}
|
||||
store.Shutdown()
|
||||
}
|
||||
Reference in new issue
Block a user