Code Monkey home page Code Monkey logo

Comments (8)

korjak avatar korjak commented on September 24, 2024 1

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.

tbicr avatar tbicr commented on September 24, 2024

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.

korjak avatar korjak commented on September 24, 2024

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.

tbicr avatar tbicr commented on September 24, 2024

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.

korjak avatar korjak commented on September 24, 2024

@tbicr how can I contribute those changes?

from django-pg-zero-downtime-migrations.

tbicr avatar tbicr commented on September 24, 2024

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.

tbicr avatar tbicr commented on September 24, 2024

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.

tbicr avatar tbicr commented on September 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.