megmut
megmut
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
Boy do I feel dumb now - what a nightmare trying to debug all that typescript 😂 Anyway, if anybody happens to come across the same thing, please check the relations closely as it's very easy to miss them when the tables are named similarly
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
// this was the error
export const tableARelations = relations(tableB, ({ many }) => ({
items: many(tableB),
}));

// when it should have been:

export const tableARelations = relations(tableA, ({ many }) => ({
items: many(tableB),
}));
// this was the error
export const tableARelations = relations(tableB, ({ many }) => ({
items: many(tableB),
}));

// when it should have been:

export const tableARelations = relations(tableA, ({ many }) => ({
items: many(tableB),
}));
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
Another relation I had declared was referencing the wrong table..
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
So I finally debugged the issue and it turned out to be the dumbest thing ever 😂
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
Eughhhhhh
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
I am using sveltekit and a few other bits of tech, so maybe that's the issue as the tsconfig extends sveltekit one and other stuff 😢 Anyway - will report here once I've found the root cause in case anybody else ever finds this
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
so.. even though the versions are the same for both orm and kit.. the typings are just nuked on my project
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
Even the type intersection
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
However, it works 100% fine 😦
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
Will make stackblitz tomorrow 🥱
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
yeah, single file didn't help 😦
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
I'm rebuilding a single schema file to try that now. Wondering if splitting each table and relations into it's own file isn't helping matters. If no joy though, I'll go create an example on stackblitz! Cheers for the help so far, will report back when I have something
23 replies
DTDrizzle Team
Created by thomasmol on 8/27/2023 in #help
Running migrate() in Sveltekit project
From memory, the --loader ts-node/esm is why you're getting 'file extension not found'
8 replies
DTDrizzle Team
Created by thomasmol on 8/27/2023 in #help
Running migrate() in Sveltekit project
Here is my Migrate script from my sveltekit project
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

const connectionString = process.env.POSTGRES_URL;

if (!connectionString) {
throw new Error('No connection string present');
}

const sql = postgres(connectionString, { max: 1, ssl: true });
const db = drizzle(sql);

await migrate(db, { migrationsFolder: './src/lib/database/drizzle' });

console.info('Migrations complete');

process.exit(0);
import { drizzle } from 'drizzle-orm/postgres-js';
import { migrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';

const connectionString = process.env.POSTGRES_URL;

if (!connectionString) {
throw new Error('No connection string present');
}

const sql = postgres(connectionString, { max: 1, ssl: true });
const db = drizzle(sql);

await migrate(db, { migrationsFolder: './src/lib/database/drizzle' });

console.info('Migrations complete');

process.exit(0);
And I invoke it with:
"db:migrate": "node -r dotenv/config --loader ts-node/esm ./src/lib/database/migrate.ts",
"db:migrate": "node -r dotenv/config --loader ts-node/esm ./src/lib/database/migrate.ts",
8 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
And used like so: export const db = drizzle(sql, { schema });
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
No description
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
Regarding the exporting - I think so yes:
- schema.ts
export { channel, channelRelations } from './tables/channel';
export { PinType, pin, pinRelations } from './tables/pin';
- schema.ts
export { channel, channelRelations } from './tables/channel';
export { PinType, pin, pinRelations } from './tables/pin';
23 replies
DTDrizzle Team
Created by megmut on 8/27/2023 in #help
Nested Relations Where has Zero Typings :confused:
Here's my relation:
export const channelRelations = relations(channel, ({ one, many }) => ({
category: one(category, {
fields: [channel.categoryId],
references: [category.id]
}),
pins: many(pin)
}));
export const channelRelations = relations(channel, ({ one, many }) => ({
category: one(category, {
fields: [channel.categoryId],
references: [category.id]
}),
pins: many(pin)
}));
23 replies