NYCPlanning / deprecated-labs-zap-api

Deprecated version of the ZAP API, see https://github.com/NYCPlanning/labs-zap-api
Other
5 stars 3 forks source link

Sync staging and production databases #68

Closed hannahkates closed 5 years ago

hannahkates commented 5 years ago

Once LUR has reviewed and approved of the new project geometry data in the staging database, we need to migrate the new table schema and data over to the production database.

ghost commented 5 years ago

1) run migration on production DB:

[10:00:37 ~/labs/apis/zap-api] (develop u=)
🏡  npm run migrate up

> labs-lucats-proxy@1.0.0 migrate /Users/juliahogan/labs/apis/zap-api
> node-pg-migrate "up"

> Migrating files:
> - 1547523580359_tables
### MIGRATION 1547523580359_tables (UP) ###
CREATE TABLE "project_geoms" (
  "projectid" varchar(10) UNIQUE PRIMARY KEY NOT NULL,
  "centroid" geometry(point),
  "polygons" geometry(multipolygon),
  "createdAt" timestamp DEFAULT current_timestamp NOT NULL,
  "updatedAt" timestamp
);
CREATE OR REPLACE FUNCTION "trigger_set_timestamp"()
  RETURNS trigger
  AS $pg1$
      BEGIN
        NEW."updatedAt" = NOW();
        RETURN NEW;
      END;
    $pg1$
  VOLATILE
  LANGUAGE plpgsql;
CREATE TRIGGER "set_timestamp"
  before update ON "project_geoms"
  FOR EACH ROW
  EXECUTE PROCEDURE "trigger_set_timestamp"();
INSERT INTO "public"."pgmigrations" (name, run_on) VALUES ('1547523580359_tables', NOW());

Migrations complete!

2) dump data from staging table

pg_dump -h zap.planninglabs.nyc -p 5431 -U postgres -W postgres -t public.project_geoms -a > project_geoms_20190130.sql

3) load data dump into production table

🏡  psql -h zap.planninglabs.nyc -p 5433 -U postgres < project_geoms_20190130.sql
Password for user postgres:
SET
SET
SET
SET
SET
 set_config
------------

(1 row)

SET
SET
SET
COPY 21484