-
-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
494d674
commit 1f79708
Showing
22 changed files
with
230 additions
and
144 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 |
---|---|---|
|
@@ -15,6 +15,8 @@ build/ | |
*.pem | ||
*.key | ||
artifacts.json | ||
.migrate | ||
.migrate-test | ||
|
||
# Yarn | ||
.pnp.* | ||
|
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,6 +1,9 @@ | ||
import run from './src/app.js'; | ||
import runMigrations from './src/migrations.js'; | ||
|
||
run().catch((err) => { | ||
console.log('Error starting app:', err); | ||
process.exit(1); | ||
}); | ||
runMigrations() | ||
.then(run) | ||
.catch((err) => { | ||
console.log('Error starting app:', err); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import getAccountDb from './src/account-db.js'; | ||
import runMigrations from './src/migrations.js'; | ||
|
||
export default async function setup() { | ||
await runMigrations(); | ||
|
||
// Insert a fake "valid-token" fixture that can be reused | ||
const db = getAccountDb(); | ||
await db.mutate('INSERT INTO sessions (token) VALUES (?)', ['valid-token']); | ||
} |
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,5 @@ | ||
import runMigrations from './src/migrations.js'; | ||
|
||
export default async function teardown() { | ||
await runMigrations('down'); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from 'node:fs/promises'; | ||
import config from '../src/load-config.js'; | ||
|
||
async function ensureExists(path) { | ||
try { | ||
await fs.mkdir(path); | ||
} catch (err) { | ||
if (err.code == 'EEXIST') { | ||
return null; | ||
} | ||
|
||
throw err; | ||
} | ||
} | ||
|
||
export const up = async function () { | ||
await ensureExists(config.serverFiles); | ||
await ensureExists(config.userFiles); | ||
}; | ||
|
||
export const down = async function () { | ||
await fs.rm(config.serverFiles, { recursive: true, force: true }); | ||
await fs.rm(config.userFiles, { recursive: true, force: true }); | ||
}; |
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,30 @@ | ||
import getAccountDb from '../src/account-db.js'; | ||
|
||
export const up = async function () { | ||
await getAccountDb().exec(` | ||
CREATE TABLE IF NOT EXISTS auth | ||
(password TEXT PRIMARY KEY); | ||
CREATE TABLE IF NOT EXISTS sessions | ||
(token TEXT PRIMARY KEY); | ||
CREATE TABLE IF NOT EXISTS files | ||
(id TEXT PRIMARY KEY, | ||
group_id TEXT, | ||
sync_version SMALLINT, | ||
encrypt_meta TEXT, | ||
encrypt_keyid TEXT, | ||
encrypt_salt TEXT, | ||
encrypt_test TEXT, | ||
deleted BOOLEAN DEFAULT FALSE, | ||
name TEXT); | ||
`); | ||
}; | ||
|
||
export const down = async function () { | ||
await getAccountDb().exec(` | ||
DROP TABLE auth; | ||
DROP TABLE sessions; | ||
DROP TABLE files; | ||
`); | ||
}; |
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,16 @@ | ||
import getAccountDb from '../src/account-db.js'; | ||
|
||
export const up = async function () { | ||
await getAccountDb().exec(` | ||
CREATE TABLE IF NOT EXISTS secrets ( | ||
name TEXT PRIMARY KEY, | ||
value BLOB | ||
); | ||
`); | ||
}; | ||
|
||
export const down = async function () { | ||
await getAccountDb().exec(` | ||
DROP TABLE secrets; | ||
`); | ||
}; |
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
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,30 @@ | ||
import migrate from 'migrate'; | ||
import config from './load-config.js'; | ||
|
||
export default function run(direction = 'up') { | ||
console.log( | ||
`Checking if there are any migrations to run for direction "${direction}"...`, | ||
); | ||
|
||
return new Promise((resolve) => | ||
migrate.load( | ||
{ | ||
stateStore: `.migrate${config.mode === 'test' ? '-test' : ''}`, | ||
}, | ||
(err, set) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
set[direction]((err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
console.log('Migrations: DONE'); | ||
resolve(); | ||
}); | ||
}, | ||
), | ||
); | ||
} |
Oops, something went wrong.