mirror of
https://github.com/djrobstep/migra.git
synced 2024-09-11 13:56:05 +03:00
simplified index/constraint output
This commit is contained in:
parent
cf6d7c0ce8
commit
ad4f2093d3
@ -96,12 +96,6 @@ def get_schema_changes(
|
||||
for t, v in added.items():
|
||||
statements.append(v.create_statement)
|
||||
|
||||
for t, v in added.items():
|
||||
statements += [i.create_statement for i in v.indexes.values()]
|
||||
|
||||
for t, v in added.items():
|
||||
statements += [c.create_statement for c in v.constraints.values()]
|
||||
|
||||
statements += get_enum_modifications(tables_from, tables_target, enums_from, enums_target)
|
||||
|
||||
for t, v in modified.items():
|
||||
@ -120,9 +114,6 @@ def get_schema_changes(
|
||||
for k, c in c_modified.items():
|
||||
statements += c.alter_table_statements(before.columns[k], t)
|
||||
|
||||
statements += statements_for_changes(before.constraints, v.constraints)
|
||||
statements += statements_for_changes(before.indexes, v.indexes)
|
||||
|
||||
return statements
|
||||
|
||||
|
||||
|
@ -45,11 +45,11 @@ class Migration(object):
|
||||
|
||||
def add_all_changes(self):
|
||||
self.add(self.changes.enums(creations_only=True, modifications=False))
|
||||
|
||||
self.add(self.changes.extensions(creations_only=True))
|
||||
|
||||
self.add(self.changes.sequences(creations_only=True))
|
||||
|
||||
self.add(self.changes.constraints(drops_only=True))
|
||||
self.add(self.changes.indexes(drops_only=True))
|
||||
self.add(self.changes.views(drops_only=True))
|
||||
self.add(self.changes.functions(drops_only=True))
|
||||
|
||||
@ -62,6 +62,9 @@ class Migration(object):
|
||||
self.add(self.changes.enums(drops_only=True, modifications=False))
|
||||
self.add(self.changes.extensions(drops_only=True))
|
||||
|
||||
self.add(self.changes.indexes(creations_only=True))
|
||||
self.add(self.changes.constraints(creations_only=True))
|
||||
|
||||
@property
|
||||
def sql(self):
|
||||
return self.statements.sql
|
||||
|
2
setup.py
2
setup.py
@ -8,7 +8,7 @@ readme = io.open('README.rst').read()
|
||||
|
||||
setup(
|
||||
name='migra',
|
||||
version='0.1.1470843990',
|
||||
version='0.1.1470915710',
|
||||
url='https://github.com/djrobstep/migra',
|
||||
description='Like diff but for PostgreSQL schemas',
|
||||
long_description=readme,
|
||||
|
@ -9,7 +9,7 @@ CREATE TYPE unused_enum AS ENUM ('a', 'b');
|
||||
CREATE TYPE usage_dropped_enum AS ENUM ('x', 'y');
|
||||
|
||||
CREATE TABLE products (
|
||||
product_no integer PRIMARY KEY,
|
||||
product_no integer,
|
||||
name varchar(10) not null unique,
|
||||
price numeric,
|
||||
x integer not null default 7,
|
||||
|
@ -1,5 +1,5 @@
|
||||
create extension hstore;
|
||||
create extension postgis;
|
||||
create extension citext;
|
||||
|
||||
CREATE TYPE shipping_status AS ENUM ('not shipped', 'shipped', 'delivered');
|
||||
|
||||
|
@ -1,13 +1,21 @@
|
||||
create type "public"."bug_status" as enum ('new', 'open', 'closed');
|
||||
|
||||
create extension "hstore" with schema "public" version '1.3';
|
||||
create extension "citext" with schema "public" version '1.1';
|
||||
|
||||
create extension "postgis" with schema "public" version '2.2.1';
|
||||
create extension "hstore" with schema "public" version '1.3';
|
||||
|
||||
create sequence "public"."bug_id_seq";
|
||||
|
||||
create sequence "public"."products_product_no_seq";
|
||||
|
||||
alter table "public"."products" drop constraint "products_name_key";
|
||||
|
||||
alter table "public"."products" drop constraint "x";
|
||||
|
||||
drop index if exists "public"."products_name_key";
|
||||
|
||||
drop index if exists "public"."products_price_idx";
|
||||
|
||||
drop view if exists "public"."vvv" cascade;
|
||||
|
||||
drop function if exists "public"."changed"(i integer, t text[]) cascade;
|
||||
@ -28,14 +36,6 @@ create table "public"."order_items" (
|
||||
);
|
||||
|
||||
|
||||
CREATE UNIQUE INDEX order_items_pkey ON order_items USING btree (product_no, order_id);
|
||||
|
||||
alter table "public"."order_items" add constraint "order_items_order_id_fkey" FOREIGN KEY (order_id) REFERENCES orders(order_id) ON DELETE CASCADE;
|
||||
|
||||
alter table "public"."order_items" add constraint "order_items_pkey" PRIMARY KEY using index "order_items_pkey";
|
||||
|
||||
alter table "public"."order_items" add constraint "order_items_product_no_fkey" FOREIGN KEY (product_no) REFERENCES products(product_no) ON DELETE RESTRICT;
|
||||
|
||||
alter table "public"."orders" alter column "status" set data type varchar;
|
||||
|
||||
drop type "public"."shipping_status";
|
||||
@ -68,26 +68,14 @@ alter table "public"."products" alter column "price" set not null;
|
||||
|
||||
alter table "public"."products" alter column "price" set default 100;
|
||||
|
||||
alter table "public"."products" alter column "product_no" set not null;
|
||||
|
||||
alter table "public"."products" alter column "product_no" set default nextval('products_product_no_seq'::regclass);
|
||||
|
||||
alter table "public"."products" alter column "x" drop not null;
|
||||
|
||||
alter table "public"."products" alter column "x" drop default;
|
||||
|
||||
alter table "public"."products" drop constraint "products_name_key";
|
||||
|
||||
alter table "public"."products" add constraint "y" CHECK ((price > (0)::numeric));
|
||||
|
||||
alter table "public"."products" drop constraint "x";
|
||||
|
||||
alter table "public"."products" add constraint "x" CHECK ((price > (10)::numeric));
|
||||
|
||||
drop index if exists "public"."products_name_key";
|
||||
|
||||
drop index if exists "public"."products_price_idx";
|
||||
|
||||
CREATE INDEX products_name_idx ON products USING btree (name);
|
||||
|
||||
create view "public"."vvv" as SELECT 2;
|
||||
|
||||
|
||||
@ -120,3 +108,21 @@ drop sequence if exists "public"."unwanted_id_seq";
|
||||
drop type "public"."unwanted_enum";
|
||||
|
||||
drop extension if exists "pg_trgm";
|
||||
|
||||
CREATE UNIQUE INDEX order_items_pkey ON order_items USING btree (product_no, order_id);
|
||||
|
||||
CREATE INDEX products_name_idx ON products USING btree (name);
|
||||
|
||||
CREATE UNIQUE INDEX products_pkey ON products USING btree (product_no);
|
||||
|
||||
alter table "public"."order_items" add constraint "order_items_order_id_fkey" FOREIGN KEY (order_id) REFERENCES orders(order_id) ON DELETE CASCADE;
|
||||
|
||||
alter table "public"."order_items" add constraint "order_items_pkey" PRIMARY KEY using index "order_items_pkey";
|
||||
|
||||
alter table "public"."order_items" add constraint "order_items_product_no_fkey" FOREIGN KEY (product_no) REFERENCES products(product_no) ON DELETE RESTRICT;
|
||||
|
||||
alter table "public"."products" add constraint "products_pkey" PRIMARY KEY using index "products_pkey";
|
||||
|
||||
alter table "public"."products" add constraint "y" CHECK ((price > (0)::numeric));
|
||||
|
||||
alter table "public"."products" add constraint "x" CHECK ((price > (10)::numeric));
|
||||
|
Loading…
Reference in New Issue
Block a user