data is malformed on drizzle-kit V 0.20.10

while running drizzle-kit generate:pg i get data is malformed errors downgrading to [email protected] fixes my issue
No description
10 Replies
Sean Cassiere
Sean Cassiere12mo 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
ScrewOP12mo ago
you want to make a github issue? or me lol
Angelelz
Angelelz12mo ago
You guys might want to take a look at this issue
Angelelz
Angelelz12mo 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
Angelelz12mo ago
It may or may not be relevant
Screw
ScrewOP12mo ago
tried install the beta version still didnt fix my issue at least
Adicco
Adicco12mo ago
Same issue here
omfj
omfj12mo 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
hugo12mo ago
was this in a release not as a breaking change or something?
grrowl
grrowl12mo 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