MCPcopy Index your code
hub / github.com/tortoise/tortoise-orm / OracleSchemaEditor

Class OracleSchemaEditor

tortoise/migrations/schema_editor/oracle.py:12–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class OracleSchemaEditor(BaseSchemaEditor):
13 DIALECT = "oracle"
14 TABLE_CREATE_TEMPLATE = "CREATE TABLE {table_name} ({fields}){extra};"
15 FIELD_TEMPLATE = '"{name}" {type} {nullable} {unique}{primary}'
16 TABLE_COMMENT_TEMPLATE = "COMMENT ON TABLE {table} IS '{comment}';"
17 COLUMN_COMMENT_TEMPLATE = "COMMENT ON COLUMN {table}.\"{column}\" IS '{comment}';"
18 INDEX_CREATE_TEMPLATE = 'CREATE INDEX "{index_name}" ON {table_name} ({fields});'
19 GENERATED_PK_TEMPLATE = '"{field_name}" {generated_sql}'
20 FK_TEMPLATE = (
21 '{constraint}FOREIGN KEY ("{db_column}")'
22 ' REFERENCES {table} ("{field}") ON DELETE {on_delete}'
23 )
24 M2M_TABLE_TEMPLATE = (
25 "CREATE TABLE {table_name} (\n"
26 ' "{backward_key}" {backward_type} NOT NULL,\n'
27 ' "{forward_key}" {forward_type} NOT NULL,\n'
28 " {backward_fk},\n"
29 " {forward_fk}\n"
30 "){extra};"
31 )
32 DELETE_TABLE_TEMPLATE = "DROP TABLE {table} CASCADE CONSTRAINTS"
33 DELETE_FIELD_TEMPLATE = 'ALTER TABLE {table} DROP COLUMN "{column}"'
34
35 def __init__(self, connection, atomic: bool = True, collect_sql: bool = False) -> None:
36 super().__init__(connection, atomic, collect_sql=collect_sql)
37 self.comments_array: list[str] = []
38 self._foreign_keys: list[str] = []
39
40 @classmethod
41 def _get_escape_translation_table(cls) -> list[str]:
42 table = super()._get_escape_translation_table()
43 table[ord("'")] = "''"
44 return table
45
46 def _get_table_comment_sql(self, table: str, comment: str) -> str:
47 sql = self.TABLE_COMMENT_TEMPLATE.format(table=table, comment=self._escape_comment(comment))
48 self.comments_array.append(sql)
49 return ""
50
51 def _get_column_comment_sql(self, table: str, column: str, comment: str) -> str:
52 sql = self.COLUMN_COMMENT_TEMPLATE.format(
53 table=table, column=column, comment=self._escape_comment(comment)
54 )
55 if sql not in self.comments_array:
56 self.comments_array.append(sql)
57 return ""
58
59 def _post_table_hook(self) -> str:
60 sql = "\n".join(self.comments_array)
61 self.comments_array = []
62 if sql:
63 return "\n" + sql
64 return ""
65
66 def _get_fk_reference_string(
67 self,
68 constraint_name: str,
69 db_field: str,

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…