Skip to content

Commit ba0ad2d

Browse files
committed
fix: Support SQLite in migration 0079_apitoken_data
Signed-off-by: Om-A-osc <omanand8132@gmail.com>
1 parent dce8dbd commit ba0ad2d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

scanpipe/migrations/0079_apitoken_data.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,23 @@ def migrate_api_tokens(apps, schema_editor):
1010
PREFIX_LENGTH = 8
1111

1212
with schema_editor.connection.cursor() as cursor:
13-
cursor.execute(
14-
"SELECT EXISTS (SELECT 1 FROM information_schema.tables "
15-
"WHERE table_name = 'authtoken_token')"
16-
)
17-
table_exists = cursor.fetchone()[0]
13+
# Check if authtoken_token table exists (works for both PostgreSQL and SQLite)
14+
db_vendor = schema_editor.connection.vendor
15+
16+
if db_vendor == 'postgresql':
17+
cursor.execute(
18+
"SELECT EXISTS (SELECT 1 FROM information_schema.tables "
19+
"WHERE table_name = 'authtoken_token')"
20+
)
21+
table_exists = cursor.fetchone()[0]
22+
elif db_vendor == 'sqlite':
23+
cursor.execute(
24+
"SELECT name FROM sqlite_master WHERE type='table' AND name='authtoken_token'"
25+
)
26+
table_exists = cursor.fetchone() is not None
27+
else:
28+
# For other databases, assume table doesn't exist
29+
table_exists = False
1830

1931
if not table_exists:
2032
return

0 commit comments

Comments
 (0)