-- Script for psql to restore the dump into a local crates.io database.
--
-- WARNING: This will destroy the current database contents.
--
-- Instructions:
--
-- 1. Create a new database and run the Diesel migrations.
--
--        createdb DATABASE_NAME
--        diesel migration run --database-url DATABASE_URL
--
-- 2. Run this script.
--
--        cd DUMP_DIRECTORY
--        psql DATABASE_URL < import.sql

BEGIN;
{{~#each tables}}
    TRUNCATE "{{this.name}}" RESTART IDENTITY CASCADE;
{{~/each}}
{{~#each tables}}
    \copy "{{this.name}}" ({{this.columns}}) FROM '{{this.name}}.csv' WITH CSV HEADER
{{~/each}}
COMMIT;

-- Script for psql to restore the dump into a local crates.io database.
--
-- WARNING: This will destroy the current database contents.
--
-- Instructions:
--
-- 1. Create a new database and run the Diesel migrations.
--
--        createdb DATABASE_NAME
--        diesel migration run --database-url DATABASE_URL
--
-- 2. Run this script.
--
--        cd DUMP_DIRECTORY
--        psql DATABASE_URL < import.sql

BEGIN;
    -- Set defaults for non-nullable columns not included in the dump.
    ALTER TABLE users ALTER COLUMN gh_access_token SET DEFAULT '';
{{#each tables}}
    TRUNCATE "{{this.name}}" RESTART IDENTITY CASCADE;
{{~/each}}
{{#each tables}}
    \copy "{{this.name}}" ({{this.columns}}) FROM '{{this.name}}.csv' WITH CSV HEADER
{{~/each}}
COMMIT;

Set default value for gh_access_token in import script.
Set default value for gh_access_token in import script.
