Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#30204 closed New feature (wontfix)

Allow declaring pre and post migration SQL on a model's Meta class

Reported by: Nikolas Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

in some cases need feature for do some SQL prior and after migration

for example:

class Meta():
   migrations.SQLBefore('truncate table logs')
   migrations.SQLAfter('insert into table logs("name") values ("initial")')

expect in migrate

RunSQL(''truncate table logs'')
.
.
.
# there what do in migrate
.
.
.
RunSQL(''insert into table logs("name") values ("initial")')

this feature very help when need some not implemented feature for example constrains or rules, or for easy create datatabse views

Change History (2)

comment:1 by Tim Graham, 5 years ago

Resolution: wontfix
Status: newclosed
Summary: Add feature for pre and post migrations SQLAllow declaring pre and post migration SQL on a model's Meta class

You can edit migrations and add operations as needed. I don't see why the operations would need to be declared on the model.

comment:2 by Simon Charette, 5 years ago

Also if you really want to perform operations after a CreateModel is performed you could register either pre_migrate or post_migrate receivers and inspect the plan to determine if it contains the operation you are looking for. See also #29843 which plans to add pre and post_operation signals to allow post_operation.connect(sender=CreateModel).

Last edited 5 years ago by Simon Charette (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top