modeling database

This commit is contained in:
2024-11-19 15:21:30 -05:00
parent c3643915ce
commit c2360fddcd
8 changed files with 61 additions and 2 deletions

1
package-lock.json generated
View File

@@ -4093,6 +4093,7 @@
"version": "0.36.3", "version": "0.36.3",
"resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.36.3.tgz", "resolved": "https://registry.npmjs.org/drizzle-orm/-/drizzle-orm-0.36.3.tgz",
"integrity": "sha512-ffQB7CcyCTvQBK6xtRLMl/Jsd5xFTBs+UTHrgs1hbk68i5TPkbsoCPbKEwiEsQZfq2I7VH632XJpV1g7LS2H9Q==", "integrity": "sha512-ffQB7CcyCTvQBK6xtRLMl/Jsd5xFTBs+UTHrgs1hbk68i5TPkbsoCPbKEwiEsQZfq2I7VH632XJpV1g7LS2H9Q==",
"license": "Apache-2.0",
"peerDependencies": { "peerDependencies": {
"@aws-sdk/client-rds-data": ">=3", "@aws-sdk/client-rds-data": ">=3",
"@cloudflare/workers-types": ">=3", "@cloudflare/workers-types": ">=3",

View File

@@ -3,9 +3,12 @@ import { sql } from "drizzle-orm";
import { timestamps } from "./columns.helpers"; import { timestamps } from "./columns.helpers";
export const accounts = pgTable("bal_accounts", { export const accounts = pgTable("bal_accounts", {
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "accountsid_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }), id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "accounts_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
first_name: varchar({ length: 40 }), first_name: varchar({ length: 40 }),
last_name: varchar({ length: 40 }), last_name: varchar({ length: 40 }),
email: varchar({length: 100}), email: varchar({length: 100}),
username: varchar({length:50}).notNull().unique(),
password_hash: varchar({length:255}).notNull().unique(),
...timestamps ...timestamps
}) })

View File

@@ -0,0 +1,9 @@
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
import { timestamps } from "./columns.helpers";
export const accounts = pgTable("base_table", {
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "base_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
...timestamps
})

View File

@@ -0,0 +1,10 @@
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
import { timestamps } from "./columns.helpers";
export const categories = pgTable("categories", {
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "categories_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
name: varchar({length: 100}).notNull(),
parent_category_id: integer(),
...timestamps
})

View File

@@ -85,4 +85,4 @@ export const lipseycatalog = pgTable("lipseycatalog", {
...timestamps ...timestamps
}); });
;

View File

@@ -0,0 +1,11 @@
import { pgTable, integer, varchar, timestamp } from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
import { timestamps } from "./columns.helpers";
export const product_feeds = pgTable("product_feeds", {
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "productfeeds_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
reseller_id: integer().notNull(),
feed_url: varchar({ length:255 }).notNull(),
last_update: timestamp(),
...timestamps
})

14
src/db/schema/products.ts Normal file
View File

@@ -0,0 +1,14 @@
import { pgTable, integer, varchar, text, decimal } from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
import { timestamps } from "./columns.helpers";
export const products = pgTable("products", {
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "products_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
name: varchar({length: 255 }).notNull(),
description: text().notNull(),
price: decimal().notNull(),
reseller_id: integer().notNull(),
category_id: integer().notNull(),
stock_qty: integer().default(0),
...timestamps
})

View File

@@ -0,0 +1,11 @@
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
import { timestamps } from "./columns.helpers";
export const resellers = pgTable("bal_resellers", {
id: integer().primaryKey().generatedAlwaysAsIdentity({ name: "resellers_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 2147483647, cache: 1 }),
name: varchar({ length: 100 }).notNull(),
website_url: varchar({ length: 255 }),
contact_email: varchar({length: 100}),
...timestamps
})