-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(model): remove the data_content field from the view user_data_list
- Loading branch information
Showing
4 changed files
with
56 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require("fs"); | ||
const knex = require("knex"); | ||
const path = require("path"); | ||
const yargs = require("yargs"); | ||
|
||
const migrateUserDataView = async (configDirectory, writeMode) => { | ||
const configPath = path.resolve(configDirectory, "mainConfig.json"); | ||
const configJSON = JSON.parse(fs.readFileSync(configPath, { encoding: "utf-8" })); | ||
|
||
const userDataSchema = path.resolve("scripts", "sql", "003-user-data.sql"); | ||
if (fs.existsSync(userDataSchema)) { | ||
const connection = await knex({ client: "pg", connection: configJSON.database }); | ||
if (await connection.schema.hasColumn("user_data_list", "data_content")) { | ||
if (writeMode) { | ||
/* Remove the view since the library cannot do it on his own */ | ||
await connection.schema.dropViewIfExists("user_data_list"); | ||
/* Read the schema again to add the view again with the latest | ||
* modification */ | ||
await connection.raw(fs.readFileSync(userDataSchema, "utf-8")); | ||
connection.destroy(); | ||
console.info(`The script ${userDataSchema} have beed executed`); | ||
} else { | ||
console.info(`Will run the script ${userDataSchema}`); | ||
} | ||
} else { | ||
console.info("The view is already up to date"); | ||
} | ||
} | ||
}; | ||
|
||
const main = async () => { | ||
const argv = yargs | ||
.alias("c", "config") | ||
.describe("c", "Path to the config directory") | ||
.alias("w", "write") | ||
.describe("w", "Write the migration in the file") | ||
.boolean("w") | ||
.demandOption(["config"]) | ||
.help().argv; | ||
|
||
console.info(argv.write ? "🚧 Prepare the migration…" : "🔧 Dry run mode…"); | ||
await migrateUserDataView(argv.config, argv.write); | ||
}; | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((err) => { | ||
console.error(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