1.0.0-beta12.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import db from "@server/db";
  2. import { configFilePath1, configFilePath2 } from "@server/lib/consts";
  3. import { sql } from "drizzle-orm";
  4. import fs from "fs";
  5. import yaml from "js-yaml";
  6. export default async function migration() {
  7. console.log("Running setup script 1.0.0-beta.12...");
  8. try {
  9. // Determine which config file exists
  10. const filePaths = [configFilePath1, configFilePath2];
  11. let filePath = "";
  12. for (const path of filePaths) {
  13. if (fs.existsSync(path)) {
  14. filePath = path;
  15. break;
  16. }
  17. }
  18. if (!filePath) {
  19. throw new Error(
  20. `No config file found (expected config.yml or config.yaml).`
  21. );
  22. }
  23. // Read and parse the YAML file
  24. let rawConfig: any;
  25. const fileContents = fs.readFileSync(filePath, "utf8");
  26. rawConfig = yaml.load(fileContents);
  27. if (!rawConfig.flags) {
  28. rawConfig.flags = {};
  29. }
  30. rawConfig.flags.allow_base_domain_resources = true;
  31. // Write the updated YAML back to the file
  32. const updatedYaml = yaml.dump(rawConfig);
  33. fs.writeFileSync(filePath, updatedYaml, "utf8");
  34. console.log(`Added new config option: allow_base_domain_resources`);
  35. } catch (e) {
  36. console.log(
  37. `Unable to add new config option: allow_base_domain_resources. This is not critical.`
  38. );
  39. console.error(e);
  40. }
  41. try {
  42. db.transaction((trx) => {
  43. trx.run(sql`ALTER TABLE 'resources' ADD 'isBaseDomain' integer;`);
  44. });
  45. console.log(`Added new column: isBaseDomain`);
  46. } catch (e) {
  47. console.log("Unable to add new column: isBaseDomain");
  48. throw e;
  49. }
  50. console.log("Done.");
  51. }