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 Cassiere14mo 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
ScrewOP14mo ago
you want to make a github issue? or me lol
Angelelz
Angelelz14mo ago
You guys might want to take a look at this issue
Angelelz
Angelelz14mo 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
Angelelz14mo ago
It may or may not be relevant
Screw
ScrewOP14mo ago
tried install the beta version still didnt fix my issue at least
Adicco
Adicco14mo ago
Same issue here
omfj
omfj14mo 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
hugo14mo ago
was this in a release not as a breaking change or something?
grrowl
grrowl14mo 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 ❤️

Did you find this page helpful?