|
@@ -20,6 +20,25 @@ import { fromZodError } from "zod-validation-error";
|
|
export default async function migration() {
|
|
export default async function migration() {
|
|
console.log("Running setup script 1.0.0-beta.9...");
|
|
console.log("Running setup script 1.0.0-beta.9...");
|
|
|
|
|
|
|
|
+ // make dir config/db/backups
|
|
|
|
+ const appPath = APP_PATH;
|
|
|
|
+ const dbDir = path.join(appPath, "db");
|
|
|
|
+
|
|
|
|
+ const backupsDir = path.join(dbDir, "backups");
|
|
|
|
+
|
|
|
|
+ // check if the backups directory exists and create it if it doesn't
|
|
|
|
+ if (!fs.existsSync(backupsDir)) {
|
|
|
|
+ fs.mkdirSync(backupsDir, { recursive: true });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // copy the db.sqlite file to backups
|
|
|
|
+ // add the date to the filename
|
|
|
|
+ const date = new Date();
|
|
|
|
+ const dateString = `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}_${date.getHours()}-${date.getMinutes()}-${date.getSeconds()}`;
|
|
|
|
+ const dbPath = path.join(dbDir, "db.sqlite");
|
|
|
|
+ const backupPath = path.join(backupsDir, `db_${dateString}.sqlite`);
|
|
|
|
+ fs.copyFileSync(dbPath, backupPath);
|
|
|
|
+
|
|
await db.transaction(async (trx) => {
|
|
await db.transaction(async (trx) => {
|
|
try {
|
|
try {
|
|
// Determine which config file exists
|
|
// Determine which config file exists
|
|
@@ -48,6 +67,12 @@ export default async function migration() {
|
|
rawConfig.server.session_cookie_name = "p_session_token"; // rename to prevent conflicts
|
|
rawConfig.server.session_cookie_name = "p_session_token"; // rename to prevent conflicts
|
|
delete rawConfig.server.resource_session_cookie_name;
|
|
delete rawConfig.server.resource_session_cookie_name;
|
|
|
|
|
|
|
|
+ if (!rawConfig.flags) {
|
|
|
|
+ rawConfig.flags = {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ rawConfig.flags.allow_raw_resources = true;
|
|
|
|
+
|
|
// Write the updated YAML back to the file
|
|
// Write the updated YAML back to the file
|
|
const updatedYaml = yaml.dump(rawConfig);
|
|
const updatedYaml = yaml.dump(rawConfig);
|
|
fs.writeFileSync(filePath, updatedYaml, "utf8");
|
|
fs.writeFileSync(filePath, updatedYaml, "utf8");
|
|
@@ -97,7 +122,7 @@ export default async function migration() {
|
|
const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
|
const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
|
const traefikConfig = yaml.load(traefikFileContents) as any;
|
|
const traefikConfig = yaml.load(traefikFileContents) as any;
|
|
|
|
|
|
- const parsedConfig = schema.safeParse(traefikConfig);
|
|
|
|
|
|
+ let parsedConfig: any = schema.safeParse(traefikConfig);
|
|
|
|
|
|
if (parsedConfig.success) {
|
|
if (parsedConfig.success) {
|
|
// Ensure websecure entrypoint exists
|
|
// Ensure websecure entrypoint exists
|
|
@@ -116,9 +141,7 @@ export default async function migration() {
|
|
const updatedTraefikYaml = yaml.dump(traefikConfig);
|
|
const updatedTraefikYaml = yaml.dump(traefikConfig);
|
|
fs.writeFileSync(traefikPath, updatedTraefikYaml, "utf8");
|
|
fs.writeFileSync(traefikPath, updatedTraefikYaml, "utf8");
|
|
|
|
|
|
- console.log(
|
|
|
|
- "Updated the version of Badger in your Traefik configuration to v1.0.0-beta.3 and added readTimeout to websecure entrypoint in your Traefik configuration.."
|
|
|
|
- );
|
|
|
|
|
|
+ console.log("Updated Badger version in Traefik config.");
|
|
} else {
|
|
} else {
|
|
console.log(fromZodError(parsedConfig.error));
|
|
console.log(fromZodError(parsedConfig.error));
|
|
console.log(
|
|
console.log(
|
|
@@ -133,6 +156,51 @@ export default async function migration() {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ try {
|
|
|
|
+ const traefikPath = path.join(
|
|
|
|
+ APP_PATH,
|
|
|
|
+ "traefik",
|
|
|
|
+ "dynamic_config.yml"
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ const schema = z.object({
|
|
|
|
+ http: z.object({
|
|
|
|
+ middlewares: z.object({
|
|
|
|
+ "redirect-to-https": z.object({
|
|
|
|
+ redirectScheme: z.object({
|
|
|
|
+ scheme: z.string(),
|
|
|
|
+ permanent: z.boolean()
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const traefikFileContents = fs.readFileSync(traefikPath, "utf8");
|
|
|
|
+ const traefikConfig = yaml.load(traefikFileContents) as any;
|
|
|
|
+
|
|
|
|
+ let parsedConfig: any = schema.safeParse(traefikConfig);
|
|
|
|
+
|
|
|
|
+ if (parsedConfig.success) {
|
|
|
|
+ // delete permanent from redirect-to-https middleware
|
|
|
|
+ delete traefikConfig.http.middlewares["redirect-to-https"].redirectScheme.permanent;
|
|
|
|
+
|
|
|
|
+ const updatedTraefikYaml = yaml.dump(traefikConfig);
|
|
|
|
+ fs.writeFileSync(traefikPath, updatedTraefikYaml, "utf8");
|
|
|
|
+
|
|
|
|
+ console.log("Deleted permanent from redirect-to-https middleware.");
|
|
|
|
+ } else {
|
|
|
|
+ console.log(fromZodError(parsedConfig.error));
|
|
|
|
+ console.log(
|
|
|
|
+ "We were unable to delete the permanent field from the redirect-to-https middleware in your Traefik configuration. Please delete it manually."
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.log(
|
|
|
|
+ "We were unable to delete the permanent field from the redirect-to-https middleware in your Traefik configuration. Please delete it manually. Note that this is not a critical change but recommended."
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
trx.run(sql`UPDATE ${users} SET email = LOWER(email);`);
|
|
trx.run(sql`UPDATE ${users} SET email = LOWER(email);`);
|
|
trx.run(
|
|
trx.run(
|
|
sql`UPDATE ${emailVerificationCodes} SET email = LOWER(email);`
|
|
sql`UPDATE ${emailVerificationCodes} SET email = LOWER(email);`
|