fordfrog / apgdiff

Another PostgreSQL Diff Tool
http://www.apgdiff.com
MIT License
355 stars 138 forks source link

Alter column - multi-definition #184

Open nicolas-lutic opened 8 years ago

nicolas-lutic commented 8 years ago

It is possible to split the alter column, because currently all definitions of a column are in the same alter. Here is an exemple origin-table:

CREATE TABLE "acl"(
    "id" CITEXT NOT NULL,
    "page_id" CITEXT NOT NULL,
    "creation_date" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
    "modification_date" TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

new-table :


CREATE TABLE "acl"(
    "id" TEXT NOT NULL,
    "page_id" TEXT NOT NULL,
    "creation_date" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "modification_date" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);

the rollout result :

ALTER TABLE acl
    ALTER COLUMN id TYPE TEXT 
    ALTER COLUMN page_id TYPE TEXT,
    ALTER COLUMN creation_date TYPE TIMESTAMP WITH TIME ZONE NOT NULL ,
    ALTER COLUMN modification_date TYPE TIMESTAMP WITH TIME ZONE NOT NULL;

This result generate an syntax error.

The right query should be :

ALTER TABLE acl
    ALTER COLUMN id TYPE TEXT 
    ALTER COLUMN page_id TYPE TEXT,
    ALTER COLUMN creation_date TYPE TIMESTAMP WITH TIME ZONE 
        ALTER COLUMN creation_date TYPE  NOT NULL ,
        ALTER COLUMN modification_date TYPE  NOT NULL,
    ALTER COLUMN modification_date TYPE TIMESTAMP WITH TIME ZONE NOT NULL;

Thanks.