-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add schema migration * add schema dump script * Add README for scripts * Add git hooks for dumping schema
- Loading branch information
1 parent
e246b68
commit 5dd55ee
Showing
66 changed files
with
2,673 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS accounts; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE accounts ( | ||
id character varying NOT NULL, | ||
data jsonb DEFAULT '{}'::jsonb NOT NULL | ||
); |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607002_add_contraint_accounts_pkey.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY accounts | ||
DROP CONSTRAINT IF EXISTS accounts_pkey; |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607002_add_contraint_accounts_pkey.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY accounts | ||
ADD CONSTRAINT accounts_pkey PRIMARY KEY (id); |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607003_create_table_account_tags.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS account_tags; |
5 changes: 5 additions & 0 deletions
5
migrations/postgres/20170607003_create_table_account_tags.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE account_tags ( | ||
account_id character varying NOT NULL, | ||
key character varying NOT NULL, | ||
value character varying | ||
); |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607004_add_constraint_account_tags_account_id_fkey.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY account_tags | ||
DROP CONSTRAINT IF EXISTS account_tags_account_id_fkey; |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607004_add_constraint_account_tags_account_id_fkey.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY account_tags | ||
ADD CONSTRAINT account_tags_account_id_fkey FOREIGN KEY (account_id) REFERENCES accounts(id); |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607005_add_index_account_tags_lookup_idx.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP INDEX IF EXISTS account_tags_lookup_idx; |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607005_add_index_account_tags_lookup_idx.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE UNIQUE INDEX account_tags_lookup_idx ON account_tags USING btree (value, key, account_id); |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607006_create_table_transactions.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS transactions; |
4 changes: 4 additions & 0 deletions
4
migrations/postgres/20170607006_create_table_transactions.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE transactions ( | ||
id character varying NOT NULL, | ||
"timestamp" timestamp without time zone NOT NULL | ||
); |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607007_add_constraint_transactions_pkey.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY transactions | ||
DROP CONSTRAINT IF EXISTS transactions_pkey; |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607007_add_constraint_transactions_pkey.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY transactions | ||
ADD CONSTRAINT transactions_pkey PRIMARY KEY (id); |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607008_add_index_timestamp_idx.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP INDEX IF EXISTS timestamp_idx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE INDEX timestamp_idx ON transactions USING brin ("timestamp"); |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607009_create_table_transaction_tags.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS transaction_tags; |
5 changes: 5 additions & 0 deletions
5
migrations/postgres/20170607009_create_table_transaction_tags.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE transaction_tags ( | ||
transaction_id character varying NOT NULL, | ||
key character varying NOT NULL, | ||
value character varying | ||
); |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607010_add_constraint_transaction_tags_transaction_id_fkey.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY transaction_tags | ||
DROP CONSTRAINT IF EXISTS transaction_tags_transaction_id_fkey; |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607010_add_constraint_transaction_tags_transaction_id_fkey.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY transaction_tags | ||
ADD CONSTRAINT transaction_tags_transaction_id_fkey FOREIGN KEY (transaction_id) REFERENCES transactions(id); |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607011_add_index_transaction_tags_lookup_idx.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP INDEX IF EXISTS transaction_tags_lookup_idx; |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607011_add_index_transaction_tags_lookup_idx.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE UNIQUE INDEX transaction_tags_lookup_idx ON transaction_tags USING btree (value, key, transaction_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS lines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE lines ( | ||
id bigint NOT NULL, | ||
transaction_id character varying NOT NULL, | ||
account_id character varying NOT NULL, | ||
delta integer NOT NULL | ||
); |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607013_add_contraint_lines_pkey.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY lines | ||
DROP CONSTRAINT IF EXISTS lines_pkey; |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607013_add_contraint_lines_pkey.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY lines | ||
ADD CONSTRAINT lines_pkey PRIMARY KEY (id); |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607014_add_contraint_lines_account_id_fkey.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY lines | ||
DROP CONSTRAINT IF EXISTS lines_account_id_fkey; |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607014_add_contraint_lines_account_id_fkey.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY lines | ||
ADD CONSTRAINT lines_account_id_fkey FOREIGN KEY (account_id) REFERENCES accounts(id); |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607015_add_constraint_lines_txn_fkey.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY lines | ||
DROP CONSTRAINT IF EXISTS lines_txn_fkey; |
2 changes: 2 additions & 0 deletions
2
migrations/postgres/20170607015_add_constraint_lines_txn_fkey.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE ONLY lines | ||
ADD CONSTRAINT lines_txn_fkey FOREIGN KEY (transaction_id) REFERENCES transactions(id); |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607016_create_sequence_lines_id_seq.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP SEQUENCE IF EXISTS lines_id_seq; |
7 changes: 7 additions & 0 deletions
7
migrations/postgres/20170607016_create_sequence_lines_id_seq.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE SEQUENCE lines_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1 | ||
OWNED BY lines.id; |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607017_alter_table_lines_column_id_set_default.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE ONLY lines ALTER COLUMN id DROP DEFAULT; |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607017_alter_table_lines_column_id_set_default.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE ONLY lines ALTER COLUMN id SET DEFAULT nextval('lines_id_seq'::regclass); |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607018_create_view_current_balances.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW IF EXISTS current_balances; |
5 changes: 5 additions & 0 deletions
5
migrations/postgres/20170607018_create_view_current_balances.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE VIEW current_balances AS | ||
SELECT lines.account_id, | ||
sum(lines.delta) AS balance | ||
FROM lines | ||
GROUP BY lines.account_id; |
1 change: 1 addition & 0 deletions
1
migrations/postgres/20170607019_create_view_invalid_transactions.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW IF EXISTS invalid_transactions; |
6 changes: 6 additions & 0 deletions
6
migrations/postgres/20170607019_create_view_invalid_transactions.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE VIEW invalid_transactions AS | ||
SELECT lines.transaction_id, | ||
sum(lines.delta) AS sum | ||
FROM lines | ||
GROUP BY lines.transaction_id | ||
HAVING (sum(lines.delta) > 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Scripts | ||
|
||
#### Install Hooks | ||
|
||
``` | ||
cd QLedger | ||
bash scripts/install_hooks.sh | ||
``` | ||
|
||
The above script install Git hooks which does the following tasks: | ||
|
||
- Identify the schema changes and dumps to `schema.sql` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Checking for DB schema changes.." | ||
DB=`echo $DATABASE_URL|cut -d/ -f4|cut -d? -f1` | ||
pg_dump -s -x -O $DB | grep -v -e "^--" -e "^$" > schema.sql | ||
SCHEMA_CHANGED=`git ls-files -m|grep schema.sql` | ||
if [ "$SCHEMA_CHANGED" != "" ]; then | ||
echo "Schema is changed and the changes are dumped to schema.sql" | ||
echo "Please add the file to Git and commit" | ||
echo "Aborted commit" | ||
exit 1 | ||
else | ||
echo "No changes in schema!" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
cp scripts/hooks/git/pre-commit .git/hooks/pre-commit | ||
chmod +x .git/hooks/pre-commit |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.