wprk14
wprk14
DTDrizzle Team
Created by Yakusho on 3/10/2024 in #help
Migrations won't run
I think it's the spread operator that's messing you up here... I have a schema.ts file in my project that just looks like this:
export * from '../../modules/addresses/address.schema';
export * from '../../modules/assets/asset.schema';
export * from '../../modules/creditors/creditor.schema';
export * from '../../modules/expenses/expense.schema';
export * from '../../modules/addresses/address.schema';
export * from '../../modules/assets/asset.schema';
export * from '../../modules/creditors/creditor.schema';
export * from '../../modules/expenses/expense.schema';
And then my schemas look like this:
import { type InferInsertModel, type InferSelectModel } from 'drizzle-orm';
import { sql } from 'drizzle-orm';
import {
doublePrecision,
pgTable,
timestamp,
uuid,
varchar,
} from 'drizzle-orm/pg-core';

import { users } from '../users/user.schema';

export const expenses = pgTable('expenses', {
id: uuid('id')
.default(sql`gen_random_uuid()`)
.notNull()
.primaryKey(),
owner: uuid('owner')
.notNull()
.references(() => users.id),
name: varchar('name').notNull(),
amount: doublePrecision('amount').notNull(),
createdAt: timestamp('created_at', { mode: 'date' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'date' }),
});

export type ExpenseCreateSchema = InferInsertModel<typeof expenses>;
export type ExpenseUpdateSchema = InferInsertModel<typeof expenses>;
export type Expense = InferSelectModel<typeof expenses>;
import { type InferInsertModel, type InferSelectModel } from 'drizzle-orm';
import { sql } from 'drizzle-orm';
import {
doublePrecision,
pgTable,
timestamp,
uuid,
varchar,
} from 'drizzle-orm/pg-core';

import { users } from '../users/user.schema';

export const expenses = pgTable('expenses', {
id: uuid('id')
.default(sql`gen_random_uuid()`)
.notNull()
.primaryKey(),
owner: uuid('owner')
.notNull()
.references(() => users.id),
name: varchar('name').notNull(),
amount: doublePrecision('amount').notNull(),
createdAt: timestamp('created_at', { mode: 'date' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'date' }),
});

export type ExpenseCreateSchema = InferInsertModel<typeof expenses>;
export type ExpenseUpdateSchema = InferInsertModel<typeof expenses>;
export type Expense = InferSelectModel<typeof expenses>;
Hopefully you can compare that to your code and work backwards from there 🙂
3 replies