fix convert-table-to-partitioned scenario

This commit is contained in:
Robert Lechte 2018-12-02 11:07:42 +11:00
parent 8061c83ead
commit b989dddcf6
4 changed files with 35 additions and 2 deletions

View File

@ -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]

View File

@ -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);

View File

@ -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);

View File

@ -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;