cyremur
cyremur2y ago

Do you have to use exactly one schema.ts?

I'm thinking about splitting up app logic schema and auth logic into two different schemas and I'm wondering whether those can be two files or if I will have to put them all in one file.
2 Replies
nipunn
nipunn2y ago
There has to be one top level schema.ts, but it is config-as-code, so you can import other files from schema.ts - so you can split your logic into multiple files and import it from schema.ts. Does that help? Hopefully I'm understanding properly, but want to double check.
Michal Srb
Michal Srb2y ago
To add to @nipunn's suggestion, you can use Object spread to include multiple tables:
// schema.ts
export default defineSchema({
...logicSchema,
...authSchema
})

// in another file
export const logicSchema = {
foos: defineTable(...),
bars: defineTable(...)
}
// etc.
// schema.ts
export default defineSchema({
...logicSchema,
...authSchema
})

// in another file
export const logicSchema = {
foos: defineTable(...),
bars: defineTable(...)
}
// etc.