enable running against a local dev database
had to add some missing tables, but it seems to work! (some known errors though, from assumptions we make e.g. blue acaras existing)
This commit is contained in:
parent
da72837d9e
commit
df2d814c13
4 changed files with 85 additions and 7 deletions
|
@ -45,7 +45,7 @@
|
||||||
"mysql-dev": "mysql --host=localhost --user=impress_2020_dev --password=impress_2020_dev --database=impress_2020_dev",
|
"mysql-dev": "mysql --host=localhost --user=impress_2020_dev --password=impress_2020_dev --database=impress_2020_dev",
|
||||||
"mysql-admin": "mysql --host=impress.openneo.net --user=matchu --password --database=openneo_impress",
|
"mysql-admin": "mysql --host=impress.openneo.net --user=matchu --password --database=openneo_impress",
|
||||||
"mysqldump": "mysqldump --host=impress.openneo.net --user=$(dotenv -p IMPRESS_MYSQL_USER) --password=$(dotenv -p IMPRESS_MYSQL_PASSWORD) --column-statistics=0",
|
"mysqldump": "mysqldump --host=impress.openneo.net --user=$(dotenv -p IMPRESS_MYSQL_USER) --password=$(dotenv -p IMPRESS_MYSQL_PASSWORD) --column-statistics=0",
|
||||||
"download-mysql-schema": "yarn --silent mysqldump --no-data openneo_impress items item_translations parents_swf_assets pet_types pet_states swf_assets | sed 's/ AUTO_INCREMENT=[0-9]*//g' > scripts/setup-mysql-dev-schema.sql && yarn --silent mysqldump openneo_impress species species_translations colors color_translations > scripts/setup-mysql-dev-constants.sql",
|
"download-mysql-schema": "yarn --silent mysqldump --no-data openneo_impress items item_translations parents_swf_assets pet_types pet_states swf_assets | sed 's/ AUTO_INCREMENT=[0-9]*//g' > scripts/setup-mysql-dev-schema.sql && yarn --silent mysqldump openneo_impress species species_translations colors color_translations zones zone_translations > scripts/setup-mysql-dev-constants.sql",
|
||||||
"setup-mysql": "yarn mysql-admin < scripts/setup-mysql.sql",
|
"setup-mysql": "yarn mysql-admin < scripts/setup-mysql.sql",
|
||||||
"setup-mysql-dev": "yarn mysql-dev < scripts/setup-mysql-dev-constants.sql && yarn mysql-dev < scripts/setup-mysql-dev-schema.sql",
|
"setup-mysql-dev": "yarn mysql-dev < scripts/setup-mysql-dev-constants.sql && yarn mysql-dev < scripts/setup-mysql-dev-schema.sql",
|
||||||
"build-cached-data": "node -r dotenv/config scripts/build-cached-data.js",
|
"build-cached-data": "node -r dotenv/config scripts/build-cached-data.js",
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -167,4 +167,4 @@ CREATE TABLE `swf_assets` (
|
||||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||||
|
|
||||||
-- Dump completed on 2020-09-19 4:19:01
|
-- Dump completed on 2020-10-06 6:09:45
|
||||||
|
|
|
@ -2,11 +2,33 @@ const mysql = require("mysql2");
|
||||||
|
|
||||||
let globalDbs = new Map();
|
let globalDbs = new Map();
|
||||||
|
|
||||||
|
// We usually run against the production database, even in local testing,
|
||||||
|
// to easily test against real data. (Not a wise general practice, but fine
|
||||||
|
// for this low-stakes project and small dev team with mostly read-only
|
||||||
|
// operations!)
|
||||||
|
//
|
||||||
|
// But you can also specify `DB_ENV=development` to use a local database,
|
||||||
|
// which is especially helpful for end-to-end modeling testing.
|
||||||
|
const defaultOptions =
|
||||||
|
process.env["DB_ENV"] === "development"
|
||||||
|
? {
|
||||||
|
host: "localhost",
|
||||||
|
user: "impress_2020_dev",
|
||||||
|
password: "impress_2020_dev",
|
||||||
|
database: "impress_2020_dev",
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
host: "impress.openneo.net",
|
||||||
|
user: process.env["IMPRESS_MYSQL_USER"],
|
||||||
|
password: process.env["IMPRESS_MYSQL_PASSWORD"],
|
||||||
|
database: "openneo_impress",
|
||||||
|
};
|
||||||
|
|
||||||
async function connectToDb({
|
async function connectToDb({
|
||||||
host = "impress.openneo.net",
|
host = defaultOptions.host,
|
||||||
user = process.env["IMPRESS_MYSQL_USER"],
|
user = defaultOptions.user,
|
||||||
password = process.env["IMPRESS_MYSQL_PASSWORD"],
|
password = defaultOptions.password,
|
||||||
database = "openneo_impress",
|
database = defaultOptions.database,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
if (globalDbs.has(host)) {
|
if (globalDbs.has(host)) {
|
||||||
return globalDbs.get(host);
|
return globalDbs.get(host);
|
||||||
|
|
Loading…
Reference in a new issue