Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created October 27, 2017 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/5022da24bf5ad01706c8cc9ca6eeac18 to your computer and use it in GitHub Desktop.
Save JoshCheek/5022da24bf5ad01706c8cc9ca6eeac18 to your computer and use it in GitHub Desktop.
pgvc demo for open source open mic
create or replace function short_hash(long_hash character(32))
returns character(10) as $$
select substring(long_hash, 0, 10)
$$ language sql; -- helper
-- pgvc "PostgreSQL Version Control"
-- it's like git for postgres!
-- some pre-existing work
select * from products;
insert into products (name, colour)
values ('boots', 'black'),
('shoes', 'white');
select * from products;
-- git config
select * from git.config_user_ref('Josh');
select * from git.init();
-- git add
select * from git.add_table('products');
-- git diff
select * from git.diff();
select action, table_name, data
from git.diff() join vc.rows using (vc_hash);
-- git log
select * from git.log();
select short_hash(vc_hash), user_ref, summary from git.log();
-- git commit
select * from git.commit('Add existing products');
-- git log
select * from git.log();
select short_hash(vc_hash), user_ref, summary from git.log();
-- git branch
select * from git.branch();
select short_hash(commit_hash), name, is_current from git.branch();
-- make a new branch
select * from git.branch('fix-boots');
select * from git.checkout('fix-boots');
-- git branch
select * from git.branch();
select short_hash(commit_hash), name, is_current from git.branch();
-- git diff
select * from git.diff();
-- update the boots
select * from products;
update products set colour = 'brown' where colour = 'black';
-- git diff
select * from git.diff();
select table_name, action, data
from git.diff() join vc.rows using (vc_hash)
order by data;
-- git commit
select * from git.commit('Fix boots colour');
-- git diff
select * from git.diff();
-- git diff master
select * from git.diff('master');
select table_name, action, data
from git.diff('master') join vc.rows using (vc_hash)
order by data;
-- current state
select * from products;
-- git checkout master
select * from git.checkout('fix-boots');
-- current state
select * from products;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment