-
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.
add cluster.js to generate schema.sql with cluster name
- Loading branch information
1 parent
1300a91
commit 17f72a8
Showing
3 changed files
with
122 additions
and
23 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 |
---|---|---|
|
@@ -141,3 +141,6 @@ cursor.lock | |
antelope-token-api | ||
|
||
*.db | ||
|
||
#SCHEMA | ||
schema.sql |
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,47 @@ | ||
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 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`, ""); | ||
} | ||
|
||
// 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