Files
HKSingleParty/02_design/schema/modify_fake_table.js
2025-05-28 09:55:51 +08:00

22 lines
864 B
JavaScript

// process fake_auth.user to auth.user
// 1. open `schema.sql`
const fs = require('fs');
const path = require('path');
var schema = fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8');
var schema_before = schema
// 2. replace `CREATE TABLE "fake_auth.users" (*)` to ''
schema = schema.replace(/CREATE TABLE "fake_auth"\."users" \(.*?\);/gs, '-- fake_auth.users part syntax removed.');
if (schema.length == schema_before.length)
console.log("cannot replace !!!")
schema_before = schema
// 3. modify `REFERENCES "fake_auth.users"` to `REFERENCES "auth.users"`
schema = schema.replace(/REFERENCES "fake_auth"\."users"/g, 'REFERENCES auth.users');
if (schema.length == schema_before.length)
console.log("cannot replace !!!")
fs.writeFileSync(path.join(__dirname, 'schema.sql'), schema);
console.log("replace fake_auth.users to auth.users done . ")