-
Notifications
You must be signed in to change notification settings - Fork 0
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
2cea9da
commit fab8c26
Showing
2 changed files
with
74 additions
and
61 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
// Replace with the actual path to your schema file | ||
const inputFilePath = path.join(__dirname, "schema.sql.example"); | ||
const outputFilePath = path.join(__dirname, "schema.sql"); | ||
|
||
// Get the cluster name from the command-line arguments | ||
const args = process.argv.slice(2); | ||
const clusterName = args[0]; // First argument after the script name | ||
|
||
if (!clusterName) { | ||
console.error( | ||
"Environment variable 'CLUSTER_NAME' is not set, Cluster and Replicated will be remove", | ||
); | ||
} | ||
|
||
// Read the schema file | ||
fs.readFile(inputFilePath, "utf8", (err, data) => { | ||
if (err) { | ||
console.error(`Error reading file: ${err}`); | ||
process.exit(1); | ||
} | ||
|
||
let modifiedData; | ||
|
||
if (clusterName) { | ||
// Replace the cluster name in the schema | ||
modifiedData = data.replace( | ||
/ON CLUSTER\s+\w+/g, | ||
`ON CLUSTER ${clusterName}`, | ||
); | ||
|
||
console.log(`Cluster name updated to: ${clusterName}`); | ||
} else { | ||
modifiedData = data.replace(/ON CLUSTER\s+\w+/g, ""); | ||
modifiedData = modifiedData.replace(/Replicated/g, ""); | ||
} | ||
|
||
// Write the modified schema to a new file | ||
fs.writeFile(outputFilePath, modifiedData, "utf8", (err) => { | ||
if (err) { | ||
console.error(`Error writing file: ${err}`); | ||
process.exit(1); | ||
} | ||
console.log("Schema updated successfully!"); | ||
}); | ||
}); |
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