Something went wrong. Try again.
A comprehensive digital solution dedicated to bridging the gap between those offering services and those seeking them, providing a centrali… gigwork.co.in
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
import { nanoid } from 'nanoid'import { sql, gte, lte } from "drizzle-orm";import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';import { timestamp } from 'drizzle-orm/mysql-core';
import { partnerIdProofTypes } from './interfaces';
// ------------------------------------------------------------------------------------------------------
// Adminexport const admin = sqliteTable('admin', { id: text().primaryKey().$default(nanoid), name: text().notNull(), email: text().notNull().unique(), password: text().notNull(), role: integer().$type('ENUM', [1, 2]).default(2).notNull(), // 1: super admin, 2: admin salt: text().notNull(), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['email'] } ] }});
// Userexport const user = sqliteTable('user', { id: text().primaryKey().$default(nanoid), name: text().notNull(), phone: text().notNull().unique(), role: integer().$type('ENUM', [1, 2]).default(2).notNull(), // 1: partner, 2: profile (business owner) status: integer().default(0).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['name'] }, { columns: ['phone'] }, { columns: ['role'] } ] }});
export const tokenTable = sqliteTable('token', { id: text().primaryKey().$default(nanoid), user_id: text().references(() => user.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), admin_id: text().references(() => admin.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), token: text().notNull().unique(), expiry: text(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['admin_id'], unique: true }, { columns: ['user_id'], unique: true }, { columns: ['token'], unique: true }, { columns: ['expires_at'] } ], constraints: [ sql`CHECK (user_id IS NOT NULL OR admin_id IS NOT NULL)` ] }});
// ------------------------------------------------------------------------------------------------------
// Categoryexport const category = sqliteTable('category', { id: text().primaryKey().$default(nanoid), name: text().notNull(), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['name'] } ] }});
// Sub Categoryexport const subCategory = sqliteTable('sub_category', { id: text().primaryKey().$default(nanoid), name: text().notNull(), category_id: text().notNull().references(() => category.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['name'] }, { columns: ['category_id'] } ] }});
// Sub Category Optionexport const subCategoryOption = sqliteTable('sub_category_option', { id: text().primaryKey().$default(nanoid), name: text().notNull(), sub_category_id: text().notNull().references(() => subCategory.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['name'] }, { columns: ['sub_category_id'] } ] }});
// ------------------------------------------------------------------------------------------------------
// Partnerexport const partner = sqliteTable('partner', { id: text().primaryKey().$default(nanoid), user_id: text().notNull().references(() => user.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), avatar: text(), referral_code: text(), address: text(), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['user_id'] }, { columns: ['referral_code'] } ] }});
// Partner Payment Infoexport const partnerBank = sqliteTable('partner_bank', { id: text().primaryKey().$default(nanoid), partner_id: text().notNull().references(() => partner.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), account_number: text().unique(), ifsc: text(), bank_name: text(), branch_name: text(), account_holder: text(), upi_id: text().unique(), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['partner_id'] }, { columns: ['account_number'] }, { columns: ['upi_id'] } ] }});
// Partner Identity Proofexport const partnerIdProof = sqliteTable('partner_id_proof', { id: text().primaryKey().$default(nanoid), partner_id: text().notNull().references(() => partner.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), proof_type_id: integer().$type('ENUM', partnerIdProofTypes.map((type) => type.id)).notNull(), proof_number: text().notNull().unique(), proof_url: text().notNull(), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['partner_id'] }, { columns: ['number'] } ] }});
// ------------------------------------------------------------------------------------------------------
// Profileexport const profile = sqliteTable('profile', { id: text().primaryKey().$default(nanoid), user_id: text().notNull().references(() => user.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), // Basic Info name: text().notNull(), slug: text().notNull().unique(), description: text(), email: text(), phone: text().unique(), // Extra phone number other than owner phone number
// Category category_id: text().notNull().references(() => category.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), sub_category_id: text().notNull().references(() => subCategory.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), sub_category_option_id: text().notNull().references(() => subCategoryOption.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}),
// Location address: text(), city: text(), state: text(), zip: text(), // pin code country: text().default('India'),
latitude: text(), longitude: text(), location_url: text(), // google maps url
operating_hours: text(), socials: text(),
// Additional details avatar: text(), banner: text(), type: integer().$type('ENUM', [1, 2, 3]).default(1).notNull(), // 1: online, 2: offline, 3: hybrid additional_services: text(), gstin: text(), partner_id: text().references(() => partner.id, {onDelete: 'SET NULL', onUpdate: 'CASCADE'}),
status: integer().default(1).notNull(), // 0: inactive, 1: active, 2: expired, 3: suspended created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['user_id'] }, { columns: ['name'] }, { columns: ['slug'] }, { columns: ['phone'] }, { columns: ['category_id'] }, { columns: ['sub_category_id'] }, { columns: ['sub_category_option_id'] }, { columns: ['city'] }, { columns: ['state'] }, { columns: ['zip'] }, { columns: ['country'] }, { columns: ['partner_id'] }, { columns: ['type'] }, { columns: ['category_id', 'sub_category_id'] }, { columns: ['additional_services'] } ] }});
// Profile Paymentexport const profilePayment = sqliteTable('profile_payment', { id: text().primaryKey().$default(nanoid), profile_id: text().notNull().references(() => profile.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}),
amount: integer().notNull(), payment_mode: text().notNull().default('cash'), payment_status: text().notNull().$type('ENUM', ['pending', 'success', 'failed']).default('pending'), transaction_id: text(), reference_id: text(), // Transaction ID from payment gateway payment_date: text(), // Date from payment gateway
status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['profile_id'] }, { columns: ['payment_mode'] }, { columns: ['payment_status'] }, { columns: ['payment_date'] }, { columns: ['created_at'] } ] }});
// Profile Mediaexport const profileMedia = sqliteTable('profile_media', { id: text().primaryKey().$default(nanoid), profile_id: text().notNull().references(() => profile.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), url: text().notNull(), description: text(), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['profile_id'] }, { columns: ['url'] } ] }});
// ------------------------------------------------------------------------------------------------------
// License Typeexport const licenseType = sqliteTable('license_type', { id: text().primaryKey().$default(nanoid), name: text().notNull().unique(), description: text(), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['name'] } ] }});
// Profile Licenseexport const profileLicense = sqliteTable('profile_license', { id: text().primaryKey().$default(nanoid), profile_id: text().notNull().references(() => profile.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), license_type_id: text().notNull().references(() => licenseType.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), license_number: text().notNull(), license_url: text(), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['profile_id'] }, { columns: ['license_type_id'] }, { columns: ['license_number'] } ] }});
// ------------------------------------------------------------------------------------------------------
// Tagsexport const tag = sqliteTable('tag', { id: text().primaryKey().$default(nanoid), name: text().notNull().unique(), category_id: text().notNull().references(() => category.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), sub_category_id: text().notNull().references(() => subCategory.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['name'] }, { columns: ['category_id'] }, { columns: ['sub_category_id'] }, { columns: ['category_id', 'sub_category_id'] } ] }});
// Profile Tagsexport const profileTag = sqliteTable('profile_tag', { id: text().primaryKey().$default(nanoid), profile_id: text().notNull().references(() => profile.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), tag_id: text().notNull().references(() => tag.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), status: integer().default(1).notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['profile_id'] }, { columns: ['tag_id'] } ] }});
// ------------------------------------------------------------------------------------------------------
// Testimonialexport const testimonial = sqliteTable('testimonial', { id: text().primaryKey().$default(nanoid), profile_id: text().notNull().references(() => profile.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), user_id: text().notNull().references(() => user.id, {onDelete: 'CASCADE', onUpdate: 'CASCADE'}), rating: integer().notNull(), status: integer().default(1).notNull(), comment: text().notNull(), created_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull(), updated_at: text().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['profile_id'] }, { columns: ['user_id'] }, { columns: ['rating'] } ], check: [ gte('rating', 1), lte('rating', 5) ] }});
// ------------------------------------------------------------------------------------------------------
// Activity Logexport const activityLog = sqliteTable('activity_log', { id: text().primaryKey().$default(nanoid), user_id: text().references(() => user.id, {onDelete: 'SET NULL', onUpdate: 'CASCADE'}), admin_id: text().references(() => admin.id, {onDelete: 'SET NULL', onUpdate: 'CASCADE'}),
path: text().notNull(), method: text().notNull(), status: integer().notNull(), activity: text(), user_agent: text(),
timestamp: timestamp().default(sql`(CURRENT_TIMESTAMP)`).notNull()}, (table) => { return { indexes: [ { columns: ['user_id'] }, { columns: ['admin_id'] }, { columns: ['path'] }, { columns: ['method'] }, { columns: ['status'] }, { columns: ['timestamp'] }, { columns: ['timestamp', 'status'] }, { columns: ['timestamp', 'user_id'] }, { columns: ['timestamp', 'admin_id'] } ], constraints: [ sql`CHECK (user_id IS NOT NULL OR admin_id IS NOT NULL)` ] }});