gonzalo123 / pgdbsync
pgdbsync
dev-master / 1.0.x-dev
2016-02-10 08:34 UTC
This package is not auto-updated.
Last update: 2024-09-24 19:29:15 UTC
README
pgdbsync 允许我们追踪不同数据库之间数据库结构的差异。它还可以创建所需的脚本以同步服务器,甚至运行脚本。
pgdbsync 命令行脚本的使用方法如下
-c [config]
-f [from database]
-t [to database]
-a [action: diff | summary | run]
使用示例
摘要
./pgdbsync -s web -f devel -t prod -a summary
HOST : production :: prod1
--------------------------------------------
function
create :: WEB.hello(varchar)
tables
create :: WEB.test
view
create :: WEB.testview
[OK] end process
创建 diff 脚本
./pgdbsync -s wf -f devel -t prod -a diff
HOST : production :: prod1
--------------------------------------------
CREATE OR REPLACE FUNCTION web.hello(item character varying)
RETURNS character varying
LANGUAGE plpgsql
AS $function$
DECLARE
BEGIN
return "Hi " || item;
END;
$function$
CREATE TABLE web.test(
test_name character NOT NULL,
test_id integer NOT NULL,
test_date timestamp without time zone NOT NULL,
CONSTRAINT pk_test PRIMARY KEY (test_date)
)
TABLESPACE web;
ALTER TABLE web.test OWNER TO user;
CREATE OR REPLACE VIEW web.testview AS
SELECT test.test_name, test.test_id, test.test_date FROM web.test WHERE (test.test_name ~~ 't%'::text);;
ALTER TABLE web.testview OWNER TO user;
[OK] end process
executing diff script
./pgdbsync -s web -f devel -t prod -a run
HOST : production :: prod1
----------------------------------
[OK] end process
creating diff script again
./pgdbsync -s wf -f devel -t prod1 -a diff
HOST : prododuction :: prod1
--------------------------------------------
drop function web.hello(varchar);
DROP TABLE web.test;
drop view web.testview;
[OK] end process
运行测试的注意事项
要本地运行测试,脚本假设以下条件
- 您有一个运行在本地的 PostgreSQL(我在测试时使用http://postgresapp.com)
- 两个名为 db1 和 db2 的空数据库
- 一个名为 "username" 的用户用于登录,密码为 "password"