-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade Node.js, group React UI tabs, add postgres (#381)
* upgrade Node.js to 22.9.0 prepare for PostgreSQL * add tortoise length recommendation * feat: group tabs in React UI * feat: add liquibase * feat: add postgres, terraform to conda * chore: add terraform gitignore * delay terraform rollout * update date on LICENSE * add extension_audio_separator * create database bootstrap * fix mms search bug, description * add MSVC check to bootstrap * add db version counter
- Loading branch information
Showing
52 changed files
with
1,053 additions
and
383 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 |
---|---|---|
|
@@ -51,3 +51,6 @@ node_modules/ | |
# Temporary files used by some modules | ||
output.wav | ||
log.out | ||
|
||
# Database | ||
/data/postgres/ |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ output.log | |
.major_version | ||
.python_version | ||
.pip_packages | ||
.db_version | ||
|
||
# Diagnostic | ||
diagnostic.txt |
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,119 @@ | ||
const fs = require("fs"); | ||
const { resolve } = require("path"); | ||
const { displayMessage } = require("./displayMessage.js"); | ||
const { $sh } = require("./shell.js"); | ||
|
||
async function applyDatabaseConfig() { | ||
const db_conf = { | ||
// location: "data/postgres", | ||
location: resolve(__dirname, "..", "..", "data", "postgres"), | ||
port: 5432, | ||
database: "webui", | ||
username: "postgres", | ||
password: "", | ||
ssl: false, | ||
}; | ||
|
||
const initializeDatabase = async () => { | ||
if (fs.existsSync(db_conf.location)) { | ||
displayMessage("Database already initialized, skipping..."); | ||
return; | ||
} | ||
displayMessage("Initializing database..."); | ||
await $sh(`initdb -D ${db_conf.location} -U ${db_conf.username}`); | ||
displayMessage("Successfully initialized database"); | ||
}; | ||
|
||
await initializeDatabase(); | ||
|
||
const withDatabase = async (func) => { | ||
const startDatabase = async () => { | ||
displayMessage("Starting database..."); | ||
await $sh(`pg_ctl start -D ${db_conf.location}`); | ||
displayMessage("Successfully started database"); | ||
}; | ||
|
||
const stopDatabase = async () => { | ||
displayMessage("Stopping database..."); | ||
await $sh(`pg_ctl stop -D ${db_conf.location} -m fast`); | ||
displayMessage("Successfully stopped database"); | ||
}; | ||
|
||
const awaitDatabase = async (counter = 0) => { | ||
try { | ||
await $sh(`pg_isready -U ${db_conf.username}`); | ||
} catch (error) { | ||
displayMessage(`Database is not ready, retrying... ${counter}/10`); | ||
if (counter < 10) { | ||
await awaitDatabase(counter + 1); | ||
} else { | ||
displayMessage("Database is not ready, aborting..."); | ||
throw error; | ||
} | ||
} | ||
}; | ||
await startDatabase(); | ||
await awaitDatabase(); | ||
try { | ||
await func(); | ||
} finally { | ||
await stopDatabase(); | ||
} | ||
}; | ||
|
||
const db_version = "1"; | ||
const db_version_file = resolve(__dirname, "..", ".db_version"); | ||
|
||
const withDatabaseVersioning = async (func) => { | ||
if (fs.existsSync(db_version_file)) { | ||
const version = fs.readFileSync(db_version_file, "utf8"); | ||
if (version === db_version) { | ||
displayMessage( | ||
`Database is already up to date version=${version}, skipping...` | ||
); | ||
return; | ||
} else { | ||
displayMessage( | ||
`Database is not up to date, current version=${version}, version=${db_version}, upgrading...` | ||
); | ||
await func(); | ||
fs.writeFileSync(db_version_file, db_version); | ||
} | ||
} | ||
}; | ||
|
||
await withDatabaseVersioning(() => | ||
withDatabase(async () => { | ||
const createDB = async () => { | ||
displayMessage(`Creating database ${db_conf.database}`); | ||
// create a database, error if it already exists | ||
try { | ||
await $sh(`createdb -U ${db_conf.username} ${db_conf.database}`); | ||
} catch (error) { | ||
displayMessage("Database already exists, skipping..."); | ||
return; | ||
} | ||
displayMessage("Successfully created database"); | ||
}; | ||
const applyMigrations = async () => { | ||
const sql = async (strings) => { | ||
// Since we're assuming no interpolated values, we can directly use the string | ||
const query = strings[0]; | ||
const psqlCommand = `psql -U ${db_conf.username} -d ${ | ||
db_conf.database | ||
} -c "${query.replace(/"/g, '\\"').replace(/\n/g, " ")}"`; | ||
$sh(psqlCommand); | ||
}; | ||
|
||
await sql`CREATE TABLE IF NOT EXISTS generations ( | ||
id SERIAL PRIMARY KEY, | ||
metadata JSONB | ||
);`; | ||
}; | ||
await createDB(); | ||
await applyMigrations(); | ||
}) | ||
); | ||
} | ||
|
||
exports.applyDatabaseConfig = applyDatabaseConfig; |
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,39 @@ | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Ignore transient lock info files created by terraform apply | ||
.terraform.tfstate.lock.info | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc | ||
|
||
.terraform.lock.hcl |
Oops, something went wrong.