MCPcopy Create free account
hub / github.com/PostHog/duckgres / loadPostgresFixtures

Method loadPostgresFixtures

tests/integration/harness.go:303–375  ·  view source on GitHub ↗

loadPostgresFixtures loads the test schema and data into PostgreSQL for comparison tests

()

Source from the content-addressed store, hash-verified

301
302// loadPostgresFixtures loads the test schema and data into PostgreSQL for comparison tests
303func (h *TestHarness) loadPostgresFixtures() error {
304 if h.PostgresDB == nil {
305 return nil
306 }
307
308 if err := h.cleanupPostgresRuntimeSchemas(); err != nil {
309 return fmt.Errorf("failed to cleanup PostgreSQL runtime schemas: %w", err)
310 }
311
312 // Drop existing objects first (in reverse dependency order)
313 dropStatements := []string{
314 "DROP VIEW IF EXISTS order_details",
315 "DROP VIEW IF EXISTS user_stats",
316 "DROP VIEW IF EXISTS active_users",
317 "DROP TABLE IF EXISTS test_schema.schema_test",
318 "DROP SCHEMA IF EXISTS test_schema CASCADE",
319 "DROP TABLE IF EXISTS array_test",
320 "DROP TABLE IF EXISTS documents",
321 "DROP TABLE IF EXISTS metrics",
322 "DROP TABLE IF EXISTS empty_table",
323 "DROP TABLE IF EXISTS nullable_test",
324 "DROP TABLE IF EXISTS json_data",
325 "DROP TABLE IF EXISTS events",
326 "DROP TABLE IF EXISTS sales",
327 "DROP TABLE IF EXISTS categories",
328 "DROP TABLE IF EXISTS order_items",
329 "DROP TABLE IF EXISTS orders",
330 "DROP TABLE IF EXISTS products",
331 "DROP TABLE IF EXISTS users",
332 "DROP TABLE IF EXISTS types_test",
333 }
334 for _, stmt := range dropStatements {
335 _, _ = h.PostgresDB.Exec(stmt)
336 }
337
338 // Read and execute schema
339 schemaPath := filepath.Join(getTestDir(), "fixtures", "schema.sql")
340 schemaSQL, err := os.ReadFile(schemaPath)
341 if err != nil {
342 return fmt.Errorf("failed to read schema: %w", err)
343 }
344
345 statements := splitSQLStatements(string(schemaSQL))
346 for _, stmt := range statements {
347 stmt = strings.TrimSpace(stmt)
348 if stmt == "" || strings.HasPrefix(stmt, "--") {
349 continue
350 }
351 if _, err := h.PostgresDB.Exec(stmt); err != nil {
352 return fmt.Errorf("failed to execute PostgreSQL schema statement: %s: %w", truncate(stmt, 50), err)
353 }
354 }
355
356 // Read and execute data
357 dataPath := filepath.Join(getTestDir(), "fixtures", "data.sql")
358 dataSQL, err := os.ReadFile(dataPath)
359 if err != nil {
360 return fmt.Errorf("failed to read data: %w", err)

Callers 1

NewTestHarnessFunction · 0.95

Calls 5

getTestDirFunction · 0.85
splitSQLStatementsFunction · 0.85
truncateFunction · 0.85
ExecMethod · 0.65

Tested by

no test coverage detected