{ "info": { "author": "Festicket", "author_email": "dev@festicket.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "django-migrate-sql-deux\n=======================\n\n.. note::\n\n This package is a fork of the ``django-migrate-sql`` package, originally published\n by Bogdan Klichuk. This package appears unmaintained, so we decided to start a fork\n as we depended on it. Most of the code is from him.\n\n|Build Status| |codecov.io|\n\nDjango Migrations support for raw SQL.\n\nAbout\n-----\n\nThis tool implements mechanism for managing changes to custom SQL\nentities (functions, types, indices, triggers) using built-in migration\nmechanism. Technically creates a sophistication layer on top of the\n``RunSQL`` Django operation.\n\nWhat it does\n------------\n\n- Makes maintaining your SQL functions, custom composite types, indices\n and triggers easier.\n- Structures SQL into configuration of **SQL items**, that are\n identified by names and divided among apps, just like models.\n- Automatically gathers and persists changes of your custom SQL into\n migrations using ``makemigrations``.\n- Properly executes backwards/forwards keeping integrity of database.\n- Create -> Drop -> Recreate approach for changes to items that do not\n support altering and require dropping and recreating.\n- Dependencies system for SQL items, which solves the problem of\n updating items, that rely on others (for example custom\n types/functions that use other custom types), and require dropping\n all dependency tree previously with further recreation.\n\nWhat it does not\n----------------\n\n- Does not parse SQL nor validate queries during ``makemigrations`` or\n ``migrate`` because is database-agnostic. For this same reason\n setting up proper dependencies is user's responsibility.\n- Does not create ``ALTER`` queries for items that support this, for\n example ``ALTER TYPE`` in Postgre SQL, because is database-agnostic.\n In case your tools allow rolling all the changes through ``ALTER``\n queries, you can consider not using this app **or** restructure\n migrations manually after creation by nesting generated operations\n into ```state_operations`` of\n ``RunSQL`` `__\n that does ``ALTER``.\n- (**TODO**)During ``migrate`` does not restore full state of items for\n analysis, thus does not notify about existing changes to schema that\n are not migrated **nor** does not recognize circular dependencies\n during migration execution.\n\nInstallation\n------------\n\nInstall from PyPi:\n\n::\n\n $ pip install django-migrate-sql-deux\n\nAdd ``migrate_sql`` to ``INSTALLED_APPS``:\n\n.. code:: python\n\n INSTALLED_APPS = [\n # ...\n 'migrate_sql',\n ]\n\nApp defines a custom ``makemigrations`` command, that inherits from\nDjango's core one, so in order ``migrate_sql`` app to kick in put it\nafter any other apps that redefine ``makemigrations`` command too.\n\nUsage\n-----\n\n1) Create ``sql_config.py`` module to root of a target app you want to\n manage custom SQL for.\n\n2) Define SQL items in it (``sql_items``), for example:\n\n.. code:: python\n\n # PostgreSQL example.\n # Let's define a simple function and let `migrate_sql` manage it's changes.\n\n from migrate_sql.config import SQLItem\n\n sql_items = [\n SQLItem(\n 'make_sum', # name of the item\n 'create or replace function make_sum(a int, b int) returns int as $$ '\n 'begin return a + b; end; ' \n '$$ language plpgsql;', # forward sql\n reverse_sql='drop function make_sum(int, int);', # sql for removal\n ),\n ]\n\n3) Create migration ``./manage.py makemigrations``:\n\n ::\n\n Migrations for 'app_name':\n 0002_auto_xxxx.py:\n - Create SQL \"make_sum\"\n\nYou can take a look at content this generated:\n\n.. code:: python\n\n # -*- coding: utf-8 -*-\n from __future__ import unicode_literals\n from django.db import migrations, models\n import migrate_sql.operations\n\n\n class Migration(migrations.Migration):\n dependencies = [\n ('app_name', '0001_initial'),\n ]\n operations = [\n migrate_sql.operations.CreateSQL(\n name='make_sum',\n sql='create or replace function make_sum(a int, b int) returns int as $$ begin return a + b; end; $$ language plpgsql;',\n reverse_sql='drop function make_sum(int, int);',\n ),\n ]\n\n4) Execute migration ``./manage.py migrate``:\n\n ::\n\n Operations to perform:\n Apply all migrations: app_name\n Running migrations:\n Rendering model states... DONE\n Applying app_name.0002_xxxx... OK\n\nCheck result in ``./manage.py dbshell``:\n\n::\n\n db_name=# select make_sum(12, 15);\n make_sum \n ----------\n 27\n (1 row)\n\nNow, say, you want to change the function implementation so that it\ntakes a custom type as argument:\n\n5) Edit your ``sql_config.py``:\n\n.. code:: python\n\n # PostgreSQL example #2.\n # Function and custom type.\n\n from migrate_sql.config import SQLItem\n\n sql_items = [\n SQLItem(\n 'make_sum', # name of the item\n 'create or replace function make_sum(a mynum, b mynum) returns mynum as $$ '\n 'begin return (a.num + b.num, 'result')::mynum; end; '\n '$$ language plpgsql;', # forward sql\n reverse_sql='drop function make_sum(mynum, mynum);', # sql for removal\n # depends on `mynum` since takes it as argument. we won't be able to drop function\n # without dropping `mynum` first.\n dependencies=[('app_name', 'mynum')],\n ),\n SQLItem(\n 'mynum' # name of the item\n 'create type mynum as (num int, name varchar(20));', # forward sql\n reverse_sql='drop type mynum;', # sql for removal\n ),\n ]\n\n6) Generate migration ``./manage.py makemigrations``:\n\n::\n\n Migrations for 'app_name':\n 0003_xxxx:\n - Reverse alter SQL \"make_sum\"\n - Create SQL \"mynum\"\n - Alter SQL \"make_sum\"\n - Alter SQL state \"make_sum\"\n\nYou can take a look at the content this generated:\n\n.. code:: python\n\n # -*- coding: utf-8 -*-\n from __future__ import unicode_literals\n from django.db import migrations, models\n import migrate_sql.operations\n\n\n class Migration(migrations.Migration):\n dependencies = [\n ('app_name', '0002_xxxx'),\n ]\n operations = [\n migrate_sql.operations.ReverseAlterSQL(\n name='make_sum',\n sql='drop function make_sum(int, int);',\n reverse_sql='create or replace function make_sum(a int, b int) returns int as $$ begin return a + b; end; $$ language plpgsql;',\n ),\n migrate_sql.operations.CreateSQL(\n name='mynum',\n sql='create type mynum as (num int, name varchar(20));',\n reverse_sql='drop type mynum;',\n ),\n migrate_sql.operations.AlterSQL(\n name='make_sum',\n sql='create or replace function make_sum(a mynum, b mynum) returns mynum as $$ begin return (a.num + b.num, \\'result\\')::mynum; end; $$ language plpgsql;',\n reverse_sql='drop function make_sum(mynum, mynum);',\n ),\n migrate_sql.operations.AlterSQLState(\n name='make_sum',\n add_dependencies=(('app_name', 'mynum'),),\n ),\n ]\n\n***NOTE:** Previous function is completely dropped before creation\nbecause definition of it changed. ``CREATE OR REPLACE`` would create\nanother version of it, so ``DROP`` makes it clean.*\n\n***If you put ``replace=True`` as kwarg to an ``SQLItem`` definition, it\nwill NOT drop + create it, but just rerun forward SQL, which is\n``CREATE OR REPLACE`` in this example.***\n\n7) Execute migration ``./manage.py migrate``:\n\n::\n\n Operations to perform:\n Apply all migrations: app_name\n Running migrations:\n Rendering model states... DONE\n Applying brands.0003_xxxx... OK\n\nCheck results:\n\n::\n\n db_name=# select make_sum((5, 'a')::mynum, (3, 'b')::mynum);\n make_sum \n ------------\n (8,result)\n (1 row)\n\n db_name=# select make_sum(12, 15);\n ERROR: function make_sum(integer, integer) does not exist\n LINE 1: select make_sum(12, 15);\n ^\n HINT: No function matches the given name and argument types. You might need to add explicit type casts.\n\nFor more examples see ``tests``.\n\nFeel free to `open new\nissues `__.\n\n.. |Build Status| image:: https://travis-ci.org/klichukb/django-migrate-sql.svg?branch=master\n :target: https://travis-ci.org/klichukb/django-migrate-sql\n.. |codecov.io| image:: https://img.shields.io/codecov/c/github/klichukb/django-migrate-sql/master.svg\n :target: https://codecov.io/github/klichukb/django-migrate-sql?branch=master", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/festicket/django-migrate-sql", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "django-migrate-sql-deux", "package_url": "https://pypi.org/project/django-migrate-sql-deux/", "platform": "", "project_url": "https://pypi.org/project/django-migrate-sql-deux/", "project_urls": { "Homepage": "https://github.com/festicket/django-migrate-sql" }, "release_url": "https://pypi.org/project/django-migrate-sql-deux/0.2.1/", "requires_dist": null, "requires_python": "", "summary": "Migration support for raw SQL in Django", "version": "0.2.1" }, "last_serial": 4676546, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "93f39ce7a93e368b88e40b6f8b5a0415", "sha256": "b85871983e9323a9c3300ccbe3366f7bd3c10015d4688f4dae9b2836c97ac169" }, "downloads": -1, "filename": "django-migrate-sql-deux-0.2.0.macosx-10.13-x86_64.tar.gz", "has_sig": false, "md5_digest": "93f39ce7a93e368b88e40b6f8b5a0415", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 44593, "upload_time": "2019-01-03T18:06:44", "url": "https://files.pythonhosted.org/packages/27/29/b4d65084b84289642348e59dbcb20d5a8a09b4346601001fa18047368512/django-migrate-sql-deux-0.2.0.macosx-10.13-x86_64.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "d11c47f607f64abe8465705b53cf931d", "sha256": "24b2913885d703dfa008bd36757211e8806d85f3906803078bd5cff56585aa9f" }, "downloads": -1, "filename": "django-migrate-sql-deux-0.2.1.tar.gz", "has_sig": false, "md5_digest": "d11c47f607f64abe8465705b53cf931d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23608, "upload_time": "2019-01-03T18:11:36", "url": "https://files.pythonhosted.org/packages/28/3c/d68259fd9bf0936eb5ff67eedef13b9c72ea893329bdf77a13d0d53921a3/django-migrate-sql-deux-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d11c47f607f64abe8465705b53cf931d", "sha256": "24b2913885d703dfa008bd36757211e8806d85f3906803078bd5cff56585aa9f" }, "downloads": -1, "filename": "django-migrate-sql-deux-0.2.1.tar.gz", "has_sig": false, "md5_digest": "d11c47f607f64abe8465705b53cf931d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23608, "upload_time": "2019-01-03T18:11:36", "url": "https://files.pythonhosted.org/packages/28/3c/d68259fd9bf0936eb5ff67eedef13b9c72ea893329bdf77a13d0d53921a3/django-migrate-sql-deux-0.2.1.tar.gz" } ] }