-
-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from Firestore to PostgreSQL (#286)
- Loading branch information
Showing
35 changed files
with
845 additions
and
351 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
# JSON string with a service account credentials for Firebase Admin SDK | ||
# https://firebase.google.com/docs/admin/setup | ||
# Service Account Key for Firebase Admin SDK | ||
# https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk | ||
|
||
FIREBASE_CREDENTIALS= | ||
FIREBASE_KEY= | ||
|
||
|
||
# Firebase config for the client-side app | ||
|
||
REACT_APP_FIREBASE={"apiKey":"AIzaSyAsuqpqt29-TIwBAu01Nbt5QnC3FIKO4A4","authDomain":"react-firebase-graphql.firebaseapp.com","databaseURL":"https://react-firebase-graphql.firebaseio.com","projectId":"react-firebase-graphql","storageBucket":"react-firebase-graphql.appspot.com","messagingSenderId":"564620986275"} | ||
|
||
|
||
# PostgreSQL settings | ||
# PostgreSQL connection settings | ||
# https://www.postgresql.org/docs/current/static/libpq-envars.html | ||
|
||
PGHOST=localhost | ||
PGUSER=postgres | ||
PGDATABASE=app | ||
PGPASSWORD= | ||
PGPORT=5432 | ||
PGSSLMODE=disable |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* React Starter Kit for Firebase | ||
* https://github.com/kriasoft/react-firebase-starter | ||
* Copyright (c) 2015-present Kriasoft | MIT License | ||
*/ | ||
|
||
'use script'; | ||
|
||
const cp = require('child_process'); | ||
|
||
let db; | ||
let status; | ||
|
||
(async () => { | ||
// Install Node.js dependencies | ||
({ status } = cp.spawnSync('yarn', ['install'], { stdio: 'inherit' })); | ||
if (status !== 0) process.exit(status); | ||
|
||
const knex = require('knex'); | ||
const config = require('../knexfile'); | ||
|
||
// Check if database already exists | ||
const database = process.env.PGDATABASE; | ||
delete process.env.PGDATABASE; | ||
|
||
db = new knex(config); | ||
|
||
const { rowCount } = await db.raw( | ||
'SELECT 1 FROM pg_database WHERE datname = ?', | ||
[database], | ||
); | ||
|
||
// If the database doesn't exist, create a new one | ||
if (!rowCount) { | ||
console.log(`Creating a new database "${database}"...`); | ||
await db.raw('CREATE DATABASE ??', [database]); | ||
} | ||
|
||
await db.destroy(); | ||
|
||
db = knex(config); | ||
process.env.PGDATABASE = database; | ||
|
||
// Make sure that the required PostgreSQL extensions are installed | ||
await db.raw('CREATE EXTENSION IF NOT EXISTS ??', ['uuid-ossp']); | ||
await db.raw('CREATE EXTENSION IF NOT EXISTS ??', ['hstore']); | ||
|
||
await db.destroy(); | ||
|
||
// Migrate database schema to the latest version | ||
({ status } = cp.spawnSync('yarn', ['db-migrate'], { stdio: 'inherit' })); | ||
if (status !== 0) process.exit(status); | ||
|
||
// Pre-compile GraphQL queries | ||
({ status } = cp.spawnSync('yarn', ['relay'], { stdio: 'inherit' })); | ||
if (status !== 0) process.exit(status); | ||
})().catch(async err => { | ||
console.error(err); | ||
if (db) await db.destroy(); | ||
process.exit(1); | ||
}); |
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
Oops, something went wrong.