Spaces:
Sleeping
Sleeping
ADD: create baseline migration for document_status and embeddings
Browse files- migrations/001_baseline.py +30 -0
migrations/001_baseline.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Baseline migration.
|
| 2 |
+
|
| 3 |
+
Already applied against Supabase (document_status/embeddings existed there
|
| 4 |
+
before this migration history existed, so this ran as a stamp - see git
|
| 5 |
+
history/commit message for that first no-op version). migratehistory tracks
|
| 6 |
+
migrations by name, not content, so filling this in with real DDL now is
|
| 7 |
+
safe: it will never re-run against Supabase, but running the full migration
|
| 8 |
+
history against a fresh database (e.g. Railway) will now actually create
|
| 9 |
+
document_status/embeddings from nothing.
|
| 10 |
+
|
| 11 |
+
Deliberately does NOT declare a foreign key to workspace(id) - workspace is
|
| 12 |
+
a Tier B table (owned by the teammate's Drizzle migrations, see
|
| 13 |
+
repositories/foreign_models.py), and this migration must be able to run
|
| 14 |
+
standalone without requiring that table to exist yet on a fresh database.
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
from repositories.models import DocumentStatus, Embedding
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def migrate(migrator, database, fake=False, **kwargs):
|
| 21 |
+
database.execute_sql("CREATE EXTENSION IF NOT EXISTS vector")
|
| 22 |
+
database.create_tables([DocumentStatus, Embedding], safe=True)
|
| 23 |
+
database.execute_sql(
|
| 24 |
+
"CREATE INDEX IF NOT EXISTS embeddings_vector_idx ON embeddings "
|
| 25 |
+
"USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100)"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def rollback(migrator, database, fake=False, **kwargs):
|
| 30 |
+
database.drop_tables([Embedding, DocumentStatus])
|