Comments (8)
Ideally, I'd like to have flag RAISE_INSTEAD_REPLACEMENT, which would work in the following way:
- if set to False: everything works the current way
- if set to True: no query replacements take place. Instead, appropriate exceptions are raised.
Basically, I'd like to be able to disable the lib's ability to replace django queries considered dangerous.
from django-pg-zero-downtime-migrations.
Can you detailly describe your case? Because this lib doing a lot of standard django queries replacement to safe one https://github.com/tbicr/django-pg-zero-downtime-migrations/blob/master/django_zero_downtime_migrations/backends/postgres/schema.py#L176-L248 - there are indexes
and unique
(create index concurrently too), fk
(require index creating concurrently to speedup fk checks), check
, not null
constraints.
Potentially you can override https://github.com/tbicr/django-pg-zero-downtime-migrations/blob/master/django_zero_downtime_migrations/backends/postgres/schema.py#L349-L363 to add logic you describe.
from django-pg-zero-downtime-migrations.
In the places you indicated, I'd like to introduce a flag for choosing whether the query should be replaced with a safe one or an exception should be raised. Can I just clone the repo, create a branch and prepare a PR with changes or I need some permissions to be granted first?
from django-pg-zero-downtime-migrations.
I not sure I understood problem you want to solve completely so it hard to suggest best option there.
As I mentioned in #44 (comment) there are a few places where query replaced with safe variant (and index created too internally) so it would be nice to have vision how they should be handled too.
from django-pg-zero-downtime-migrations.
@tbicr how can I contribute those changes?
from django-pg-zero-downtime-migrations.
it looks quite complicated to cover all cases library do standard query replacing or not, that also can be related to django version or settings. I think about different approach to check real sql, like sqlmigrate
and get result using real sql for standard django and this lib comparison, but I don't dig it yet.
from django-pg-zero-downtime-migrations.
there are some examples running sqlmigrate
for tests INSTALLED_APPS += ['tests.apps.good_flow_app']
DB_ENGINE=django.db.backends.postgresql
:
% DJANGO_SETTINGS_MODULE=tests.settings venv/bin/python manage.py sqlmigrate good_flow_app 0004
System check identified some issues:
WARNINGS:
good_flow_app.RelatedTestTable: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
good_flow_app.TestTable: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL
--
-- Alter field field on testtable
--
UPDATE "good_flow_app_testtable" SET "field" = 0 WHERE "field" IS NULL; SET CONSTRAINTS ALL IMMEDIATE;
ALTER TABLE "good_flow_app_testtable" ALTER COLUMN "field" SET NOT NULL;
--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL
DB_ENGINE=django_zero_downtime_migrations.backends.postgres
:
% DJANGO_SETTINGS_MODULE=tests.settings venv/bin/python manage.py sqlmigrate good_flow_app 0004
System check identified some issues:
WARNINGS:
good_flow_app.RelatedTestTable: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
good_flow_app.TestTable: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL
--
-- Alter field field on testtable
--
UPDATE "good_flow_app_testtable" SET "field" = 0 WHERE "field" IS NULL; SET CONSTRAINTS ALL IMMEDIATE;
ALTER TABLE "good_flow_app_testtable" ADD CONSTRAINT "good_flow_app_testtable_field_c3f3a507_notnull" CHECK ("field" IS NOT NULL) NOT VALID;
ALTER TABLE "good_flow_app_testtable" VALIDATE CONSTRAINT "good_flow_app_testtable_field_c3f3a507_notnull";
ALTER TABLE "good_flow_app_testtable" ALTER COLUMN "field" SET NOT NULL;
ALTER TABLE "good_flow_app_testtable" DROP CONSTRAINT "good_flow_app_testtable_field_c3f3a507_notnull";
--
-- Raw Python operation
--
-- THIS OPERATION CANNOT BE WRITTEN AS SQL
So looks it's better option to achieve you want with maximal coverage.
from django-pg-zero-downtime-migrations.
same for index:
DB_ENGINE=django.db.backends.postgresql
:
% DJANGO_SETTINGS_MODULE=tests.settings venv/bin/python manage.py sqlmigrate good_flow_app 0022
System check identified some issues:
WARNINGS:
good_flow_app.RelatedTestTable: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
good_flow_app.TestTable: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
BEGIN;
--
-- Create index test_index on field(s) test_field_int of model testtable
--
CREATE INDEX "test_index" ON "good_flow_app_testtable" ("test_field_int");
COMMIT;
DB_ENGINE=django_zero_downtime_migrations.backends.postgres
:
% DJANGO_SETTINGS_MODULE=tests.settings venv/bin/python manage.py sqlmigrate good_flow_app 0022
System check identified some issues:
WARNINGS:
good_flow_app.RelatedTestTable: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
good_flow_app.TestTable: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.
HINT: Configure the DEFAULT_AUTO_FIELD setting or the AppConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.
BEGIN;
--
-- Create index test_index on field(s) test_field_int of model testtable
--
CREATE INDEX CONCURRENTLY "test_index" ON "good_flow_app_testtable" ("test_field_int");
COMMIT;
from django-pg-zero-downtime-migrations.
Related Issues (15)
- Postgis support HOT 3
- migrations.DeleteModel locks DB when it has ForeignKey field HOT 5
- Unchanged `db_table` in `RenameModel` raises `Unsafe.ALTER_TABLE_RENAME`
- Publish release to pypi? HOT 2
- Do you have a workflow for running `prettier` on markdown files? HOT 7
- Django 4.1: `'DatabaseSchemaEditor'` has no attribute `'sql_create_sequence'` HOT 2
- DatabaseSchemaEditorMixin._alter_column_type_sql() takes 5 positional arguments but 7 were given HOT 1
- Drop support for Python 3.6 HOT 4
- When migrating DB from scratch, early ran deferred SQL queries crash HOT 2
- Django 2.2 and PostgreSQL 11 HOT 6
- AttributeError on django v3.2 HOT 4
- Add column and set default may be a safe action HOT 5
- Is package really still beta? HOT 4
- Using django-pg-zero-downtime-migrations our table is locked HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-pg-zero-downtime-migrations.