Load the test schema once and truncate data between files.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3c0213ae74
commit
79e4fd0d4b
8 files changed
+78
-25
No files matched your search
@@ -89,6 +89,7 @@ def _require_test_database() -> None:
|
||||
def reset_postgres_schema() -> None:
|
||||
import psycopg
|
||||
|
||||
from db_init import mark_schema_dirty
|
||||
from sql_compat import postgres_connect_kwargs
|
||||
|
||||
kwargs = postgres_connect_kwargs()
|
||||
@@ -103,6 +104,36 @@ def reset_postgres_schema() -> None:
|
||||
conn.execute("GRANT ALL ON SCHEMA public TO CURRENT_USER")
|
||||
finally:
|
||||
conn.close()
|
||||
mark_schema_dirty()
|
||||
|
||||
|
||||
def reset_postgres_data() -> None:
|
||||
"""Clear rows on kansho_test without reloading schema.sql."""
|
||||
import psycopg
|
||||
|
||||
from sql_compat import postgres_connect_kwargs
|
||||
|
||||
kwargs = postgres_connect_kwargs()
|
||||
if "conninfo" in kwargs:
|
||||
conn = psycopg.connect(kwargs["conninfo"], autocommit=True)
|
||||
else:
|
||||
conn = psycopg.connect(autocommit=True, **kwargs)
|
||||
try:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT tablename FROM pg_tables
|
||||
WHERE schemaname = 'public' AND tablename <> 'schema_migrations'
|
||||
"""
|
||||
).fetchall()
|
||||
names = [row[0] for row in rows]
|
||||
if names:
|
||||
joined = ", ".join('"' + name.replace('"', '""') + '"' for name in names)
|
||||
conn.execute(f"TRUNCATE TABLE {joined} RESTART IDENTITY CASCADE")
|
||||
finally:
|
||||
conn.close()
|
||||
from db import refresh_runtime_seed
|
||||
|
||||
refresh_runtime_seed()
|
||||
|
||||
|
||||
def configure_test_engine() -> None:
|
||||
|
||||
Reference in new issue
Block a user