|
| 1 | +import { sql } from 'drizzle-orm'; |
| 2 | +import { |
| 3 | + inet, |
| 4 | + integer, |
| 5 | + numeric, |
| 6 | + pgTable, |
| 7 | + serial, |
| 8 | + text, |
| 9 | + timestamp, |
| 10 | + varchar, |
| 11 | +} from 'drizzle-orm/pg-core'; |
| 12 | + |
| 13 | +export const accountTypes = pgTable('AccountTypes', { |
| 14 | + name: text('name').primaryKey().notNull(), |
| 15 | + interestRate: numeric('interest_rate', { precision: 4, scale: 3 }).notNull(), |
| 16 | + transactionFee: numeric('transaction_fee', { |
| 17 | + precision: 4, |
| 18 | + scale: 3, |
| 19 | + }).notNull(), |
| 20 | +}); |
| 21 | + |
| 22 | +export const paymentTypes = pgTable('PaymentTypes', { |
| 23 | + name: text('name').primaryKey().notNull(), |
| 24 | +}); |
| 25 | + |
| 26 | +export const roles = pgTable('Roles', { |
| 27 | + name: text('name').primaryKey().notNull(), |
| 28 | +}); |
| 29 | + |
| 30 | +export const transactionStatuses = pgTable('TransactionStatuses', { |
| 31 | + name: text('name').primaryKey().notNull(), |
| 32 | +}); |
| 33 | + |
| 34 | +export const transactionTypes = pgTable('TransactionTypes', { |
| 35 | + name: text('name').primaryKey().notNull(), |
| 36 | +}); |
| 37 | + |
| 38 | +export const users = pgTable('Users', { |
| 39 | + id: serial('id').primaryKey().notNull(), |
| 40 | + accountType: text('account_type') |
| 41 | + .notNull() |
| 42 | + .references(() => accountTypes.name), |
| 43 | + minecraftUuid: varchar('minecraft_uuid', { length: 36 }), |
| 44 | + minecraftUsername: varchar('minecraft_username', { length: 16 }), |
| 45 | + discordUsername: varchar('discord_username', { length: 32 }), |
| 46 | + password: varchar('password', { length: 60 }).notNull(), |
| 47 | + createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) |
| 48 | + .default(sql`now() AT TIME ZONE 'utc'`) |
| 49 | + .notNull(), |
| 50 | + updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) |
| 51 | + .default(sql`now() AT TIME ZONE 'utc'`) |
| 52 | + .notNull(), |
| 53 | + lastSignInAt: timestamp('last_sign_in_at', { |
| 54 | + withTimezone: true, |
| 55 | + mode: 'string', |
| 56 | + }), |
| 57 | + lastDiscordChangeAt: timestamp('last_discord_change_at', { |
| 58 | + withTimezone: true, |
| 59 | + mode: 'string', |
| 60 | + }), |
| 61 | + lastPasswordChangeAt: timestamp('last_password_change_at', { |
| 62 | + withTimezone: true, |
| 63 | + mode: 'string', |
| 64 | + }), |
| 65 | + lastIpAccessed: inet('last_ip_accessed'), |
| 66 | +}); |
| 67 | + |
| 68 | +export const transactions = pgTable('Transactions', { |
| 69 | + id: serial('id').primaryKey().notNull(), |
| 70 | + userId: integer('user_id') |
| 71 | + .notNull() |
| 72 | + .references(() => users.id), |
| 73 | + createdByUserId: integer('created_by_user_id') |
| 74 | + .notNull() |
| 75 | + .references(() => users.id), |
| 76 | + amount: numeric('amount', { precision: 32, scale: 2 }).notNull(), |
| 77 | + fee: numeric('fee', { precision: 32, scale: 2 }).default('0.00').notNull(), |
| 78 | + transactionType: text('transaction_type') |
| 79 | + .notNull() |
| 80 | + .references(() => transactionTypes.name), |
| 81 | + paymentType: text('payment_type') |
| 82 | + .notNull() |
| 83 | + .references(() => paymentTypes.name), |
| 84 | + attachment: text('attachment'), |
| 85 | + note: text('note'), |
| 86 | + status: text('status') |
| 87 | + .notNull() |
| 88 | + .references(() => transactionStatuses.name), |
| 89 | + createdAt: timestamp('created_at', { withTimezone: true, mode: 'string' }) |
| 90 | + .default(sql`now() AT TIME ZONE 'utc'`) |
| 91 | + .notNull(), |
| 92 | + updatedAt: timestamp('updated_at', { withTimezone: true, mode: 'string' }) |
| 93 | + .default(sql`now() AT TIME ZONE 'utc'`) |
| 94 | + .notNull(), |
| 95 | +}); |
0 commit comments