使用Sqitch Rework命令更改表 [英] Altering Table with Sqitch Rework command
问题描述
我已经尝试过多次追踪 Sqitch的' postgres教程,只是不更改功能(使用 CREATE或REPLACE FUNCTION
)而已,更改表中的字段名称,以查看部署后如何对其进行锻炼。但是最终出现以下错误。有人可以向我指出正确的方向吗?
I've tried several times to follow Sqitch's 'postgres tutorial', just except instead of altering a function (which uses CREATE OR REPLACE FUNCTION
), I'm changing a field name in a table to see how it'll workout after a deployment. But it ends up with below error. Could someone please point me to the right direction?
$ sqitch verify
Verifying sqtest_db
* appschema .... ok
* contact ...... ok
Undeployed change:
* contact
Verify successful
$ sqitch deploy
Deploying changes to sqtest_db
+ contact .. psql:deploy/contact.sql:10: ERROR: relation "contact" already exists
not ok
"/usr/local/bin/psql" unexpectedly returned exit value 3
Deploy failed
此是我在被标记
之前和在被标记
部署查询之后
This is my before tagged
and after tagged
deploy query
在标记数据库之前
BEGIN;
CREATE TABLE sq_schema.contact
(
log_date DATE NOT NULL,
emp_name CHARACTER VARYING(100) DEFAULT ''
);
COMMIT;
使用
sqitch rework contact --requires appschema -n 'Added CONTACT table'
标记
BEGIN;
CREATE TABLE sq_schema.contact
(
log_date DATE NOT NULL,
-- Change field name,
employee_name CHARACTER VARYING(100) DEFAULT ''
);
COMMIT;
推荐答案
返工用于制作幂等更改,例如创建或替换功能
。 CREATE TABLE
语句不是幂等的。如果要向表中添加列,我建议:
Rework is intended for making idempotent changes, such as CREATE OR REPLACE FUNCTION
. The CREATE TABLE
statement is not idempotent. If you want to add a column to a table, I suggest either:
-
如果尚未发布数据库,只需修改原始更改中的
CREATE TABLE
语句和sqitch rebase
还原所有更改并使用更新的表重新部署。
If you have not released your database, just modify the
CREATE TABLE
statement in the original change andsqitch rebase
to revert all changes and redeploy with the updated table. This is ideal when doing development.
否则,添加一个名为 $ table_ $ column
的新更改。或类似的内容,然后使用 ALTER TABLE
语句以添加新列。如果您已经发布了数据库,则可以采用这种方法,但是如果您愿意,也可以在发布之前进行操作。
Otherwise, add a new change, named $table_$column
or some such, and use an ALTER TABLE
statement to add the new column. This is the approach to take if you have released the database already, though you can also do it before release if you like.
这篇关于使用Sqitch Rework命令更改表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!