data is malformed on drizzle-kit V 0.20.10

while running drizzle-kit generate:pg i get data is malformed errors downgrading to drizzle-kit@0.20.9 fixes my issue
No description
10 Replies
Sean Cassiere
Sean Cassiere9mo ago
Same here. Something has changed between 0.20.9 and 0.20.10 which has broken the generate:pg command, where it crashes on the reading of the snapshot files.
Screw
Screw9mo ago
you want to make a github issue? or me lol
Angelelz
Angelelz9mo ago
You guys might want to take a look at this issue
Angelelz
Angelelz9mo ago
GitHub
[BUG]: how to recover from snapshot.json data is malformed · Issue ...
What version of drizzle-orm are you using? latest What version of drizzle-kit are you using? latest Describe the Bug When trying drizzle-kit generate:sqlite --config drizzle.config.ts I get drizzle...
Angelelz
Angelelz9mo ago
It may or may not be relevant
Screw
Screw9mo ago
tried install the beta version still didnt fix my issue at least
Adicco
Adicco9mo ago
Same issue here
omfj
omfj9mo ago
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`);
});
})();
hugo
hugo9mo ago
was this in a release not as a breaking change or something?
grrowl
grrowl9mo ago
hitting this as well 😦 beta hasn't fixed the issue and push doesn't work because type "serial" does not exist (postgres)... this script fixed it, thank you so much ❤️
Want results from more Discord servers?
Add your server