This commit is contained in:
@@ -97,47 +97,6 @@ export const clients = sqliteTable(
|
||||
}),
|
||||
);
|
||||
|
||||
export const timeEntries = sqliteTable(
|
||||
"time_entries",
|
||||
{
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
userId: text("user_id").notNull(),
|
||||
organizationId: text("organization_id").notNull(),
|
||||
clientId: text("client_id").notNull(),
|
||||
startTime: integer("start_time", { mode: "timestamp" }).notNull(),
|
||||
endTime: integer("end_time", { mode: "timestamp" }),
|
||||
description: text("description"),
|
||||
invoiceId: text("invoice_id"),
|
||||
isManual: integer("is_manual", { mode: "boolean" }).default(false),
|
||||
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(
|
||||
() => new Date(),
|
||||
),
|
||||
},
|
||||
(table: any) => ({
|
||||
userFk: foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [users.id],
|
||||
}),
|
||||
orgFk: foreignKey({
|
||||
columns: [table.organizationId],
|
||||
foreignColumns: [organizations.id],
|
||||
}),
|
||||
clientFk: foreignKey({
|
||||
columns: [table.clientId],
|
||||
foreignColumns: [clients.id],
|
||||
}),
|
||||
userIdIdx: index("time_entries_user_id_idx").on(table.userId),
|
||||
organizationIdIdx: index("time_entries_organization_id_idx").on(
|
||||
table.organizationId,
|
||||
),
|
||||
clientIdIdx: index("time_entries_client_id_idx").on(table.clientId),
|
||||
startTimeIdx: index("time_entries_start_time_idx").on(table.startTime),
|
||||
invoiceIdIdx: index("time_entries_invoice_id_idx").on(table.invoiceId),
|
||||
}),
|
||||
);
|
||||
|
||||
export const tags = sqliteTable(
|
||||
"tags",
|
||||
{
|
||||
@@ -163,26 +122,50 @@ export const tags = sqliteTable(
|
||||
}),
|
||||
);
|
||||
|
||||
export const timeEntryTags = sqliteTable(
|
||||
"time_entry_tags",
|
||||
export const timeEntries = sqliteTable(
|
||||
"time_entries",
|
||||
{
|
||||
timeEntryId: text("time_entry_id").notNull(),
|
||||
tagId: text("tag_id").notNull(),
|
||||
id: text("id")
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
userId: text("user_id").notNull(),
|
||||
organizationId: text("organization_id").notNull(),
|
||||
clientId: text("client_id").notNull(),
|
||||
tagId: text("tag_id"),
|
||||
startTime: integer("start_time", { mode: "timestamp" }).notNull(),
|
||||
endTime: integer("end_time", { mode: "timestamp" }),
|
||||
description: text("description"),
|
||||
invoiceId: text("invoice_id"),
|
||||
isManual: integer("is_manual", { mode: "boolean" }).default(false),
|
||||
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(
|
||||
() => new Date(),
|
||||
),
|
||||
},
|
||||
(table: any) => ({
|
||||
pk: primaryKey({ columns: [table.timeEntryId, table.tagId] }),
|
||||
timeEntryFk: foreignKey({
|
||||
columns: [table.timeEntryId],
|
||||
foreignColumns: [timeEntries.id],
|
||||
userFk: foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [users.id],
|
||||
}),
|
||||
orgFk: foreignKey({
|
||||
columns: [table.organizationId],
|
||||
foreignColumns: [organizations.id],
|
||||
}),
|
||||
clientFk: foreignKey({
|
||||
columns: [table.clientId],
|
||||
foreignColumns: [clients.id],
|
||||
}),
|
||||
tagFk: foreignKey({
|
||||
columns: [table.tagId],
|
||||
foreignColumns: [tags.id],
|
||||
}),
|
||||
timeEntryIdIdx: index("time_entry_tags_time_entry_id_idx").on(
|
||||
table.timeEntryId,
|
||||
userIdIdx: index("time_entries_user_id_idx").on(table.userId),
|
||||
organizationIdIdx: index("time_entries_organization_id_idx").on(
|
||||
table.organizationId,
|
||||
),
|
||||
tagIdIdx: index("time_entry_tags_tag_id_idx").on(table.tagId),
|
||||
clientIdIdx: index("time_entries_client_id_idx").on(table.clientId),
|
||||
tagIdIdx: index("time_entries_tag_id_idx").on(table.tagId),
|
||||
startTimeIdx: index("time_entries_start_time_idx").on(table.startTime),
|
||||
invoiceIdIdx: index("time_entries_invoice_id_idx").on(table.invoiceId),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user