mirror of
https://github.com/djrobstep/migra.git
synced 2024-09-11 13:56:05 +03:00
drop expression
support
This commit is contained in:
parent
3ff01951b2
commit
da6671acae
@ -276,7 +276,17 @@ def get_table_changes(
|
|||||||
|
|
||||||
inheritance_status_changed = c.is_inherited != c_before.is_inherited
|
inheritance_status_changed = c.is_inherited != c_before.is_inherited
|
||||||
|
|
||||||
if inheritance_status_changed or generated_status_changed:
|
generated_status_removed = not c.is_generated and c_before.is_generated
|
||||||
|
|
||||||
|
can_drop_generated = (
|
||||||
|
generated_status_removed and c_before.can_drop_generated
|
||||||
|
)
|
||||||
|
|
||||||
|
drop_and_recreate_required = inheritance_status_changed or (
|
||||||
|
generated_status_changed and not can_drop_generated
|
||||||
|
)
|
||||||
|
|
||||||
|
if drop_and_recreate_required:
|
||||||
del c_modified[k]
|
del c_modified[k]
|
||||||
|
|
||||||
if not c_before.is_inherited:
|
if not c_before.is_inherited:
|
||||||
@ -285,6 +295,9 @@ def get_table_changes(
|
|||||||
if not c.is_inherited:
|
if not c.is_inherited:
|
||||||
c_added[k] = c
|
c_added[k] = c
|
||||||
|
|
||||||
|
if generated_status_changed:
|
||||||
|
pass
|
||||||
|
|
||||||
for k, c in c_removed.items():
|
for k, c in c_removed.items():
|
||||||
alter = v.alter_table_statement(c.drop_column_clause)
|
alter = v.alter_table_statement(c.drop_column_clause)
|
||||||
statements.append(alter)
|
statements.append(alter)
|
||||||
|
6
poetry.lock
generated
6
poetry.lock
generated
@ -334,7 +334,7 @@ jupyter = ["ipywidgets (>=7.5.1,<8.0.0)"]
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "schemainspect"
|
name = "schemainspect"
|
||||||
version = "3.1.1663062229"
|
version = "3.1.1663480743"
|
||||||
description = "Schema inspection for PostgreSQL (and possibly others)"
|
description = "Schema inspection for PostgreSQL (and possibly others)"
|
||||||
category = "main"
|
category = "main"
|
||||||
optional = false
|
optional = false
|
||||||
@ -742,8 +742,8 @@ rich = [
|
|||||||
{file = "rich-12.5.1.tar.gz", hash = "sha256:63a5c5ce3673d3d5fbbf23cd87e11ab84b6b451436f1b7f19ec54b6bc36ed7ca"},
|
{file = "rich-12.5.1.tar.gz", hash = "sha256:63a5c5ce3673d3d5fbbf23cd87e11ab84b6b451436f1b7f19ec54b6bc36ed7ca"},
|
||||||
]
|
]
|
||||||
schemainspect = [
|
schemainspect = [
|
||||||
{file = "schemainspect-3.1.1663062229-py3-none-any.whl", hash = "sha256:ca6ab497e90a1e4c4dd7406b1d38efdbf478d7c482408e3a8852b2dfa686a5f6"},
|
{file = "schemainspect-3.1.1663480743-py3-none-any.whl", hash = "sha256:852813d0ee38985242373708b8441c5fbcff611d30dae013afb5cb7d7148c95a"},
|
||||||
{file = "schemainspect-3.1.1663062229.tar.gz", hash = "sha256:625507658f4971a4a3cd0a4afe7ce40e66158fe5fcbd57f426e307434f5742e6"},
|
{file = "schemainspect-3.1.1663480743.tar.gz", hash = "sha256:b042676ceffd189983f38a42042dfb19d86925f8c4f8bdd6d40334582fdb116b"},
|
||||||
]
|
]
|
||||||
six = [
|
six = [
|
||||||
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
|
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
|
||||||
|
@ -14,7 +14,7 @@ python = ">=3.7,<4"
|
|||||||
sqlbag = "*"
|
sqlbag = "*"
|
||||||
six = "*"
|
six = "*"
|
||||||
# schemainspect = {path="../schemainspect", develop=true}
|
# schemainspect = {path="../schemainspect", develop=true}
|
||||||
schemainspect = ">=3.1.1658648837"
|
schemainspect = ">=3.1.1663480743"
|
||||||
psycopg2-binary = { version="*", optional = true }
|
psycopg2-binary = { version="*", optional = true }
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
|
15
tests/FIXTURES/generated/a.sql
Normal file
15
tests/FIXTURES/generated/a.sql
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
-- create table t(
|
||||||
|
-- a int,
|
||||||
|
-- adding int,
|
||||||
|
-- modifying int generated always as identity,
|
||||||
|
-- removing int generated by default as identity
|
||||||
|
-- );
|
||||||
|
|
||||||
|
create table t();
|
||||||
|
|
||||||
|
CREATE TABLE "demo_gencol" (
|
||||||
|
"id" serial PRIMARY KEY, -- PRIMARY KEY
|
||||||
|
"the_column" TEXT NULL GENERATED ALWAYS AS ('the original generated value') STORED, -- The column that is originally GENERATED, then changed not to be
|
||||||
|
"the_column2" text
|
||||||
|
);
|
||||||
|
|
0
tests/FIXTURES/generated/additions.sql
Normal file
0
tests/FIXTURES/generated/additions.sql
Normal file
17
tests/FIXTURES/generated/b.sql
Normal file
17
tests/FIXTURES/generated/b.sql
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
-- create table t(
|
||||||
|
-- a int,
|
||||||
|
-- adding int generated always as (1) stored,
|
||||||
|
-- modifying int generated always as (1) stored,
|
||||||
|
-- removing int
|
||||||
|
-- );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE "demo_gencol" (
|
||||||
|
"id" serial PRIMARY KEY, -- PRIMARY KEY
|
||||||
|
"the_column" text,
|
||||||
|
"the_column2" TEXT NULL GENERATED ALWAYS AS ('the original generated value') STORED -- The column that is originally GENERATED, then changed not to be
|
||||||
|
);
|
||||||
|
|
7
tests/FIXTURES/generated/expected.sql
Normal file
7
tests/FIXTURES/generated/expected.sql
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
drop table "public"."t";
|
||||||
|
|
||||||
|
alter table "public"."demo_gencol" drop column "the_column2";
|
||||||
|
|
||||||
|
alter table "public"."demo_gencol" add column "the_column2" text generated always as ('the original generated value'::text) stored;
|
||||||
|
|
||||||
|
alter table "public"."demo_gencol" alter column "the_column" drop expression;
|
0
tests/FIXTURES/generated/expected2.sql
Normal file
0
tests/FIXTURES/generated/expected2.sql
Normal file
13
tests/FIXTURES/generated_added/a.sql
Normal file
13
tests/FIXTURES/generated_added/a.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
-- create table t(
|
||||||
|
-- a int,
|
||||||
|
-- adding int,
|
||||||
|
-- modifying int generated always as identity,
|
||||||
|
-- removing int generated by default as identity
|
||||||
|
-- );
|
||||||
|
|
||||||
|
create table t();
|
||||||
|
|
||||||
|
CREATE TABLE "demo_gencol" (
|
||||||
|
"id" serial PRIMARY KEY , -- PRIMARY KEY
|
||||||
|
"the_column" TEXT NULL -- The column that is originally GENERATED, then changed not to be
|
||||||
|
);
|
0
tests/FIXTURES/generated_added/additions.sql
Normal file
0
tests/FIXTURES/generated_added/additions.sql
Normal file
13
tests/FIXTURES/generated_added/b.sql
Normal file
13
tests/FIXTURES/generated_added/b.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
-- create table t(
|
||||||
|
-- a int,
|
||||||
|
-- adding int generated always as (1) stored,
|
||||||
|
-- modifying int generated always as (1) stored,
|
||||||
|
-- removing int
|
||||||
|
-- );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE "demo_gencol" (
|
||||||
|
"id" serial PRIMARY KEY , -- PRIMARY KEY
|
||||||
|
"the_column" TEXT NULL -- The column that is originally GENERATED, then changed not to be
|
||||||
|
);
|
1
tests/FIXTURES/generated_added/expected.sql
Normal file
1
tests/FIXTURES/generated_added/expected.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
alter table "public"."demo_gencol" alter column "the_column" drop expression;
|
0
tests/FIXTURES/generated_added/expected2.sql
Normal file
0
tests/FIXTURES/generated_added/expected2.sql
Normal file
@ -11,11 +11,9 @@ create table "public"."t2" (
|
|||||||
|
|
||||||
alter table "public"."gen" drop column "adding";
|
alter table "public"."gen" drop column "adding";
|
||||||
|
|
||||||
alter table "public"."gen" drop column "removing";
|
|
||||||
|
|
||||||
alter table "public"."gen" add column "adding" integer generated always as (1) stored;
|
alter table "public"."gen" add column "adding" integer generated always as (1) stored;
|
||||||
|
|
||||||
alter table "public"."gen" add column "removing" integer;
|
alter table "public"."gen" alter column "removing" drop expression;
|
||||||
|
|
||||||
alter table "public"."identchanges" alter column "c" drop default;
|
alter table "public"."identchanges" alter column "c" drop default;
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ dependencies2
|
|||||||
dependencies3
|
dependencies3
|
||||||
dependencies4
|
dependencies4
|
||||||
constraints
|
constraints
|
||||||
|
generated
|
||||||
""".split()
|
""".split()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user