This commit is contained in:
phaichayon
2026-04-26 00:15:22 +07:00
parent a330abf9b6
commit 043edff93a
64 changed files with 25076 additions and 461 deletions

View File

@@ -0,0 +1,40 @@
// db/schema/location.ts
import {
pgTable,
uuid,
varchar,
text,
timestamp,
index,
} from "drizzle-orm/pg-core";
export const locations = pgTable(
"ms_locations",
{
id: uuid("id").defaultRandom().primaryKey(),
branchId: text("branch_id").notNull(), // Multi-tenant support
code: varchar("code", { length: 255 }).notNull(),
nameTh: varchar("name_th", { length: 255 }).notNull(),
nameEn: varchar("name_en", { length: 255 }),
type: varchar("type", { length: 50 }).notNull(),
// 'country' | 'province' | 'district' | 'subdistrict'
parentId: uuid("parent_id"), // self reference (tree)
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
},
(table) => ({
branchIdx: index("ms_locations_branch_id_idx").on(table.branchId),
typeIndex: index("ms_locations_type_idx").on(table.type),
parentIdIndex: index("ms_locations_parent_id_idx").on(table.parentId),
branchTypeIdx: index("ms_locations_branch_type_idx").on(
table.branchId,
table.type,
),
}),
);
export type Location = typeof locations.$inferSelect;
export type NewLocation = typeof locations.$inferInsert;