-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pizza): sync down users from production (#1370)
* break: sync from production * chore: remove deprecated file * chore: remove long time deprecated file this script was used to migrate the database from Vultr to AWS it had been committed Just Because we might need it sometime we never needed if after that so better to remove the clutter * fix: update staging sync to use new script
- Loading branch information
Showing
14 changed files
with
108 additions
and
876 deletions.
There are no files selected for viewing
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# seed-database | ||
|
||
This script uses a read-only database user to selectively sync data from a production database to a local development database. | ||
|
||
This is useful for having production-grade data both locally and on ephemeral pizza links (i.e. vultr servers that are spun up for each Pull Request). |
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,26 @@ | ||
#!/usr/bin/env bash | ||
# This is the script that runs inside the container | ||
# Usage: container.sh <local_pg_url> <remote_pg_url> | ||
|
||
# cd to this script's directory | ||
cd "$(dirname "$0")" || exit | ||
|
||
set -ex | ||
|
||
LOCAL_PG="$1" | ||
REMOTE_PG="$2" | ||
|
||
# fetch users | ||
psql --command="\\COPY (SELECT * FROM users) TO '/tmp/users.csv' (FORMAT CSV, DELIMITER ';')" "${REMOTE_PG}" | ||
|
||
# fetch teams | ||
psql --command="\\COPY (SELECT id, name, slug, theme, settings, domain FROM teams) TO '/tmp/teams.csv' (FORMAT CSV, DELIMITER ';')" "${REMOTE_PG}" | ||
|
||
# fetch flows | ||
psql --command="\\COPY (SELECT * FROM flows) TO '/tmp/flows.csv' (FORMAT CSV, DELIMITER ';')" "${REMOTE_PG}" | ||
|
||
# fetch published_flows (the last two) | ||
psql --command="\\COPY (SELECT id, data, flow_id, summary, publisher_id FROM (SELECT id, data, flow_id, summary, publisher_id, ROW_NUMBER() OVER (PARTITION BY flow_id ORDER BY created_at DESC) as row_num FROM published_flows) as subquery WHERE row_num <= 2) TO '/tmp/published_flows.csv' (FORMAT CSV);" "${REMOTE_PG}" | ||
|
||
# run container.sql | ||
psql "${LOCAL_PG}" < container.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,34 @@ | ||
BEGIN; | ||
|
||
TRUNCATE TABLE users, teams CASCADE; | ||
|
||
\COPY users FROM '/tmp/users.csv' (FORMAT CSV, DELIMITER ';'); | ||
|
||
\COPY teams (id, name, slug, theme, settings, domain) FROM '/tmp/teams.csv' (FORMAT CSV, DELIMITER ';') | ||
|
||
\COPY flows FROM '/tmp/flows.csv' (FORMAT CSV, DELIMITER ';'); | ||
UPDATE flows SET version = 1; | ||
|
||
-- insert an operation for each flow (to make sharedb happy) | ||
INSERT INTO operations (flow_id, data, version) | ||
SELECT | ||
id | ||
, json_build_object( | ||
'm', json_build_object( | ||
'ts', extract(epoch from now()) * 1000 | ||
, 'uId', '1' | ||
) | ||
, 'v', 0 | ||
, 'seq', 1 | ||
, 'src', '1' | ||
, 'create', json_build_object( | ||
'data', '{}' | ||
, 'type', 'http://sharejs.org/types/JSONv0' | ||
) | ||
) | ||
, 1 | ||
FROM flows; | ||
|
||
\COPY published_flows (id, data, flow_id, summary, publisher_id) FROM '/tmp/published_flows.csv' (FORMAT CSV); | ||
|
||
COMMIT; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.