Skip to content

Commit

Permalink
Updated get_sql_for_connection to read from SQL files
Browse files Browse the repository at this point in the history
  • Loading branch information
arnav13081994 authored and jleclanche committed Jan 26, 2023
1 parent edfccc1 commit c016cee
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sql/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from pathlib import Path


def get_sql_for_connection(schema_editor, direction: str) -> str:
"""
Returns the vendor and the collection of SQL Statements depending on:
Expand All @@ -6,10 +9,17 @@ def get_sql_for_connection(schema_editor, direction: str) -> str:
2. Direction of Migrations: forward or Backward
"""
vendor = schema_editor.connection.vendor
# Construct Path to SQL
file_path = (
Path(__file__).parent
/ "custom_migrations"
/ f"migrate_{vendor}_{direction}.sql"
)
try:
return vendor, CUSTOM_SQL[vendor][direction]
except KeyError as error:
sql_statement = Path(file_path).read_text()
except FileNotFoundError as error:
# In case it's oracle or some other django supported db that we do not support yet.
raise RuntimeError(
f"We currently do not support {vendor}. Please open an issue at https://github.com/dj-stripe/dj-stripe/issues/new?assignees=&labels=discussion&template=feature-or-enhancement-proposal.md&title= if you'd like it supported.",
) from error
return vendor, sql_statement

0 comments on commit c016cee

Please sign in to comment.