omfj
omfj
Explore posts from servers
SSolidJS
Created by omfj on 7/14/2024 in #support
How do get Cloudflare bindings in dev?
Thank you, @Tommypop !
4 replies
DTDrizzle Team
Created by Screw on 1/6/2024 in #help
data is malformed on drizzle-kit V 0.20.10
I fixed it by running this script. Note: This script would not work if you use other schemas than public.
import { promises as fs } from "fs";

/**
* Migrates all the snapshots in `./drizzle/migrations/meta` to add the `schemaTo` property to all the foreign keys.
*
* drizzle-kit version 0.20.9 to 0.20.10
*/

const META_FOLDER = "./drizzle/migrations/meta";

void (async () => {
const snapshots = await fs.readdir(META_FOLDER).then((files) => {
return files.filter((file) => file.endsWith("snapshot.json"));
});

snapshots.forEach(async (snapshot) => {
const snapshotFile = await fs
.readFile(`${META_FOLDER}/${snapshot}`, "utf-8")
.then((file) => JSON.parse(file));

const tables = Object.keys(snapshotFile.tables);

tables.forEach((table) => {
const foreignKeys = Object.keys(snapshotFile["tables"][table]?.foreignKeys ?? {});

foreignKeys.forEach((foreignKey) => {
snapshotFile["tables"][table]["foreignKeys"][foreignKey]["schemaTo"] = "public";
});
});

await fs.writeFile(`${META_FOLDER}/${snapshot}`, `${JSON.stringify(snapshotFile, null, 2)}\n`);
});
})();
import { promises as fs } from "fs";

/**
* Migrates all the snapshots in `./drizzle/migrations/meta` to add the `schemaTo` property to all the foreign keys.
*
* drizzle-kit version 0.20.9 to 0.20.10
*/

const META_FOLDER = "./drizzle/migrations/meta";

void (async () => {
const snapshots = await fs.readdir(META_FOLDER).then((files) => {
return files.filter((file) => file.endsWith("snapshot.json"));
});

snapshots.forEach(async (snapshot) => {
const snapshotFile = await fs
.readFile(`${META_FOLDER}/${snapshot}`, "utf-8")
.then((file) => JSON.parse(file));

const tables = Object.keys(snapshotFile.tables);

tables.forEach((table) => {
const foreignKeys = Object.keys(snapshotFile["tables"][table]?.foreignKeys ?? {});

foreignKeys.forEach((foreignKey) => {
snapshotFile["tables"][table]["foreignKeys"][foreignKey]["schemaTo"] = "public";
});
});

await fs.writeFile(`${META_FOLDER}/${snapshot}`, `${JSON.stringify(snapshotFile, null, 2)}\n`);
});
})();
13 replies