0

在阅读了sqitch-rework文档和Altering Table with Sqitch Rework command stackoverflow 问题后,我知道这sqitch-rework是用于幂等更改的。

但为什么?

似乎我对sqitch-rework非幂等变化的使用效果很好。

这是我在 PostgreSQL 中使用它的方式:

原始部署:

-- Deploy myproject:database/facility/schema/public/table/mytable to pg
-- requires: database/facility/schema/public

SET ROLE :"owner_role";

BEGIN;

CREATE TABLE public."MyTable"(
  "Date" timestamp without time zone NOT NULL
);

COMMIT;

原始还原:

-- Revert myproject:database/facility/schema/public/table/mytable from pg

SET ROLE :"owner_role";

BEGIN;

DROP TABLE public."MyTable";

COMMIT;

重新部署:

-- Deploy myproject:database/facility/schema/public/table/mytable to pg
-- requires: database/facility/schema/public

SET ROLE :"owner_role";

BEGIN;

LOCK TABLE public."MyTable" IN ACCESS EXCLUSIVE MODE;

ALTER TABLE public."MyTable" RENAME COLUMN "Date" TO "Complete time";

ALTER TABLE public."MyTable" ADD COLUMN "Start time" timestamp without time zone;
UPDATE public."MyTable" SET "Start time" = "Complete time";
ALTER TABLE public."MyTable" ALTER COLUMN "Start time" SET NOT NULL;

COMMIT;

重做还原:

-- Revert myproject:database/facility/schema/public/table/mytable from pg

SET ROLE :"owner_role";

BEGIN;

LOCK TABLE public."MyTable" IN ACCESS EXCLUSIVE MODE;

ALTER TABLE public."MyTable" DROP COLUMN "Start time";
ALTER TABLE public."MyTable" RENAME COLUMN "Complete time" TO "Date";

COMMIT;

我不明白什么吗?这不是有效的使用sqitch-rework吗?

4

0 回答 0