-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🛂 Add backup and restore database scripts
- Loading branch information
1 parent
d80cc1b
commit 3645607
Showing
10 changed files
with
107 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,6 @@ firebaseServiceAccount.json | |
tags | ||
|
||
dump.sql | ||
dump.tar | ||
|
||
__env.js |
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,22 @@ | ||
import { exec } from 'child_process' | ||
import { promptAndSetEnvironment } from './utils' | ||
|
||
const backupDatabase = async () => { | ||
await promptAndSetEnvironment() | ||
exec( | ||
`pg_dump ${process.env.DATABASE_URL} -F c > dump.tar`, | ||
(error, stdout, stderr) => { | ||
if (error) { | ||
console.log(`error: ${error.message}`) | ||
return | ||
} | ||
if (stderr) { | ||
console.log(`stderr: ${stderr}`) | ||
return | ||
} | ||
console.log(`stdout: ${stdout}`) | ||
} | ||
) | ||
} | ||
|
||
backupDatabase() |
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
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,9 @@ | ||
import { PrismaClient } from 'db' | ||
import { promptAndSetEnvironment } from './utils' | ||
|
||
const executePlayground = async () => { | ||
await promptAndSetEnvironment() | ||
const prisma = new PrismaClient({ log: ['query', 'info', 'warn', 'error'] }) | ||
} | ||
|
||
executePlayground() |
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,23 @@ | ||
import { exec } from 'child_process' | ||
import { promptAndSetEnvironment } from './utils' | ||
|
||
const restoreDatabase = async () => { | ||
await promptAndSetEnvironment() | ||
|
||
exec( | ||
`pg_restore -d ${process.env.DATABASE_URL} -c dump.tar`, | ||
(error, stdout, stderr) => { | ||
if (error) { | ||
console.log(`error: ${error.message}`) | ||
return | ||
} | ||
if (stderr) { | ||
console.log(`stderr: ${stderr}`) | ||
return | ||
} | ||
console.log(`stdout: ${stdout}`) | ||
} | ||
) | ||
} | ||
|
||
restoreDatabase() |
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,27 @@ | ||
import { join } from 'path' | ||
import prompts from 'prompts' | ||
import { isEmpty } from 'utils' | ||
|
||
export const promptAndSetEnvironment = async () => { | ||
const response = await prompts({ | ||
type: 'select', | ||
name: 'env', | ||
message: 'Pick an environment', | ||
choices: [ | ||
{ | ||
title: 'Local', | ||
value: 'local', | ||
}, | ||
{ title: 'Staging', value: 'staging' }, | ||
{ title: 'Production', value: 'production' }, | ||
], | ||
initial: 0, | ||
}) | ||
|
||
if (isEmpty(response.env)) process.exit() | ||
|
||
require('dotenv').config({ | ||
override: true, | ||
path: join(__dirname, `.env.${response.env}`), | ||
}) | ||
} |
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