|
22 | 22 |
|
23 | 23 |
|
24 | 24 | class DatabaseSchemaEditor(schema.DatabaseSchemaEditor): |
25 | | - # The PostgreSQL backend uses "SET CONSTRAINTS ... IMMEDIATE" before |
26 | | - # "ALTER TABLE..." to run any any deferred checks to allow dropping the |
27 | | - # foreign key in the same transaction. This doesn't apply to Aurora DSQL. |
28 | | - sql_delete_fk = "" |
| 25 | + """ |
| 26 | + Aurora DSQL schema editor based on the PostgreSQL backend. |
| 27 | + |
| 28 | + Aurora DSQL is PostgreSQL-compatible but supports a subset of PostgreSQL |
| 29 | + operations. This class overrides SQL templates and methods to work within |
| 30 | + DSQL's constraints. |
| 31 | + """ |
29 | 32 |
|
30 | | - # ALTER TABLE ADD CONSTRAINT PRIMARY KEY is not supported |
31 | | - sql_create_pk = "" |
| 33 | + # Use DSQL's async index creation syntax. |
| 34 | + sql_create_index = ( |
| 35 | + "CREATE INDEX ASYNC %(name)s ON %(table)s%(using)s " |
| 36 | + "(%(columns)s)%(include)s%(extra)s%(condition)s" |
| 37 | + ) |
| 38 | + |
| 39 | + # Create unique constraints as unique indexes instead of using "ALTER TABLE". |
| 40 | + sql_create_unique = "CREATE UNIQUE INDEX ASYNC %(name)s ON %(table)s (%(columns)s)" |
32 | 41 |
|
33 | | - # "ALTER TABLE ... DROP CONSTRAINT ..." not supported for dropping UNIQUE |
34 | | - # constraints; must use this instead. |
| 42 | + # Delete unique constraints by dropping the underlying index. |
35 | 43 | sql_delete_unique = "DROP INDEX %(name)s CASCADE" |
36 | 44 |
|
37 | | - # The PostgreSQL backend uses "SET CONSTRAINTS ... IMMEDIATE" after this |
38 | | - # statement. This isn't supported by Aurora DSQL. |
| 45 | + # Remove constraint management from default updates. |
39 | 46 | sql_update_with_default = ( |
40 | 47 | "UPDATE %(table)s SET %(column)s = %(default)s WHERE %(column)s IS NULL" |
41 | 48 | ) |
42 | 49 |
|
43 | | - # ALTER TABLE ADD CONSTRAINT is not supported |
44 | | - sql_create_unique = "" |
45 | | - |
46 | | - # ALTER TABLE ADD CONSTRAINT FOREIGN KEY is not supported |
| 50 | + # These "ALTER TABLE" operations are not supported. |
| 51 | + sql_create_pk = "" |
47 | 52 | sql_create_fk = "" |
48 | | - # ALTER TABLE ADD CONSTRAINT CHECK is not supported |
| 53 | + sql_delete_fk = "" |
49 | 54 | sql_create_check = "" |
50 | 55 | sql_delete_check = "" |
51 | | - # ALTER TABLE DROP CONSTRAINT is not supported |
52 | 56 | sql_delete_constraint = "" |
53 | | - # ALTER TABLE DROP COLUMN is not supported |
54 | 57 | sql_delete_column = "" |
55 | 58 |
|
56 | 59 | def __enter__(self): |
|
0 commit comments