mirror of
https://github.com/djrobstep/migra.git
synced 2024-09-11 13:56:05 +03:00
fix convert-table-to-partitioned scenario
This commit is contained in:
parent
8061c83ead
commit
b989dddcf6
@ -156,8 +156,16 @@ def get_table_changes(tables_from, tables_target, enums_from, enums_target):
|
||||
|
||||
for t, v in modified.items():
|
||||
before = tables_from[t]
|
||||
|
||||
# drop/recreate tables which have changed from partitioned to non-partitioned
|
||||
if v.is_partitioned != before.is_partitioned:
|
||||
statements.append(v.drop_statement)
|
||||
statements.append(v.create_statement)
|
||||
continue
|
||||
|
||||
# attach/detach tables with changed parent tables
|
||||
statements += v.attach_detach_statements(before)
|
||||
if v.parent_table != before.parent_table:
|
||||
statements += v.attach_detach_statements(before)
|
||||
|
||||
for t, v in modified.items():
|
||||
before = tables_from[t]
|
||||
|
@ -12,3 +12,7 @@ CREATE TABLE measurement_y2006m03 PARTITION OF measurement
|
||||
FOR VALUES FROM ('2006-03-01') TO ('2006-04-01');
|
||||
|
||||
CREATE INDEX ON measurement_y2006m02 (logdate);
|
||||
|
||||
CREATE TABLE reg2partitioned( city_id int not null, logdate date not null, peaktemp int, unitsales int);
|
||||
|
||||
CREATE TABLE partitioned2reg( city_id int not null, logdate date not null, peaktemp int, unitsales int ) PARTITION BY RANGE (logdate);
|
||||
|
@ -16,5 +16,6 @@ CREATE TABLE measurement_y2006m03 (
|
||||
unitsales int
|
||||
);
|
||||
|
||||
CREATE TABLE reg2partitioned( city_id int not null, logdate date not null, peaktemp int, unitsales int) PARTITION BY RANGE (logdate);
|
||||
|
||||
--CREATE INDEX ON measurement (logdate);
|
||||
CREATE TABLE partitioned2reg( city_id int not null, logdate date not null, peaktemp int, unitsales int);
|
||||
|
@ -2,4 +2,24 @@ drop index if exists "public"."measurement_y2006m02_logdate_idx";
|
||||
|
||||
alter table "public"."measurement" detach partition "public"."measurement_y2006m03";
|
||||
|
||||
drop table "public"."partitioned2reg";
|
||||
|
||||
create table "public"."partitioned2reg" (
|
||||
"city_id" integer not null,
|
||||
"logdate" date not null,
|
||||
"peaktemp" integer,
|
||||
"unitsales" integer
|
||||
);
|
||||
|
||||
|
||||
drop table "public"."reg2partitioned";
|
||||
|
||||
create table "public"."reg2partitioned" (
|
||||
"city_id" integer not null,
|
||||
"logdate" date not null,
|
||||
"peaktemp" integer,
|
||||
"unitsales" integer
|
||||
) partition by RANGE (logdate);
|
||||
|
||||
|
||||
alter table "public"."measurement" add column "extra" text;
|
||||
|
Loading…
Reference in New Issue
Block a user