-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into share-email-field
- Loading branch information
Showing
11 changed files
with
59 additions
and
21 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# This is only needed for automatically generating types from the database | ||
# using `kysely-codegen`. See the following: | ||
# https://github.com/RobinBlomberg/kysely-codegen?tab=readme-ov-file#generating-type-definitions | ||
DATABASE_URL=postgresql://localhost:5432/colorstack | ||
DATABASE_URL=postgresql://colorstack:colorstack@localhost:5432/colorstack | ||
ENVIRONMENT=development |
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
11 changes: 11 additions & 0 deletions
11
packages/core/src/infrastructure/database/scripts/setup.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,11 @@ | ||
-- Cleans up any existing databases/users. | ||
|
||
DROP DATABASE IF EXISTS colorstack; | ||
DROP DATABASE IF EXISTS colorstack_test; | ||
DROP ROLE IF EXISTS colorstack; | ||
|
||
-- Creates new databases and users. | ||
|
||
CREATE ROLE colorstack WITH SUPERUSER LOGIN PASSWORD 'colorstack'; | ||
CREATE DATABASE colorstack OWNER colorstack; | ||
CREATE DATABASE colorstack_test OWNER colorstack |
33 changes: 33 additions & 0 deletions
33
packages/core/src/infrastructure/database/scripts/setup.ts
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,33 @@ | ||
import { exec } from 'child_process'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
import { ENV } from '@/shared/env'; | ||
|
||
if (ENV.ENVIRONMENT !== 'development') { | ||
throw new Error('Cannot setup database in non-development environment.'); | ||
} | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
// This is the full path to the `setup.sql` file. | ||
const pathToInitFile = path.join(__dirname, 'setup.sql'); | ||
|
||
exec( | ||
`psql -U postgres -d postgres -f ${pathToInitFile}`, | ||
(error, stdout, stderr) => { | ||
if (stdout) { | ||
console.log(stdout); | ||
} | ||
|
||
if (stderr) { | ||
// Log but don't throw for notices/warnings. | ||
console.warn(stderr); | ||
} | ||
|
||
if (error) { | ||
throw new Error(`psql exited with error: ${error}`); | ||
} | ||
} | ||
); |
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