Skip to content

Commit

Permalink
refactor: Update constants and database schema for equipment attributes
Browse files Browse the repository at this point in the history
- Update the limits in the constants file to include new attribute lengths
- Add new tables for equipment types, equipment groups, and equipment attributes
- Update the equipment table to include new columns for description, weight, type, and group
- Create relationships between equipment, equipment types, equipment groups, and equipment attributes
- Add new table for equipment attribute values
- Update existing tables to use integer columns instead of ULID for foreign keys
  • Loading branch information
Perdolique committed Sep 22, 2024
1 parent a31efdf commit 7d64542
Show file tree
Hide file tree
Showing 37 changed files with 1,224 additions and 894 deletions.
2 changes: 1 addition & 1 deletion app/components/equipment/EquipmentTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import EmptyContent from './EmptyContent.vue';
export interface EquipmentItem {
readonly id: string;
readonly id: number;
readonly name: string;
readonly weight: number;
}
Expand Down
4 changes: 2 additions & 2 deletions app/composables/use-checklist-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ChecklistItemModel } from "~/models/checklist";
export function useChecklistStore() {
const items = useState<ChecklistItemModel[]>('checklistItems', () => [])

async function removeItem(checklistId: string, itemId: string) {
async function removeItem(checklistId: string, itemId: number) {
try {
const deletedItem = await $fetch(`/api/checklists/${checklistId}/items/${itemId}`, {
method: 'DELETE'
Expand All @@ -15,7 +15,7 @@ export function useChecklistStore() {
}
}

async function addItem(checklistId: string, equipmentId: string) {
async function addItem(checklistId: string, equipmentId: number) {
try {
const insertedItem = await $fetch(`/api/checklists/${checklistId}/items`, {
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion app/composables/use-equipment-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useDebounceFn } from '@vueuse/core';
import type { EquipmentItem } from '~/components/equipment/EquipmentTable.vue';

interface EquipmentData {
readonly id: string;
readonly id: number;
readonly name: string | null;
readonly weight: number;
readonly createdAt: string;
Expand Down
2 changes: 1 addition & 1 deletion app/composables/use-user-equipment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface EquipmentItem {
readonly id: string;
readonly id: number;
readonly name: string;
readonly weight: number;
readonly createdAt: string;
Expand Down
4 changes: 2 additions & 2 deletions app/models/checklist.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
interface ChecklistEquipment {
readonly id: string;
readonly id: number;
readonly name: string;
readonly weight: number;
}

export interface ChecklistItemModel {
readonly id: string;
readonly id: number;
readonly equipment: ChecklistEquipment;
}
4 changes: 2 additions & 2 deletions app/pages/checklists/[checklistId].vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
})
interface InventoryItem {
readonly id: string;
readonly id: number;
readonly name: string;
}
Expand Down Expand Up @@ -166,7 +166,7 @@
}
}
async function handleOptionClick(equipmentId: string) {
async function handleOptionClick(equipmentId: number) {
await addItem(checklistId, equipmentId)
options.value = options.value.filter(({ id }) => id !== equipmentId)
Expand Down
2 changes: 1 addition & 1 deletion app/pages/inventory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import PerdSearch from '~/components/PerdSearch/PerdSearch.vue';
interface EquipmentItem {
readonly id: string;
readonly id: number;
readonly name: string;
readonly weight: number;
readonly createdAt: string;
Expand Down
9 changes: 7 additions & 2 deletions constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export const publicApiPaths = [
]

export const limits = {
maxUserNameLength: 32,
maxEquipmentItemNameLength: 64,
maxChecklistNameLength: 32,
maxEquipmentItemNameLength: 64,
maxEquipmentTypeNameLength: 32,
maxEquipmentGroupNameLength: 32,
maxEquipmentAttributeNameLength: 32,
maxOAuthProviderTypeLength: 32,
maxOAuthProviderNameLength: 32,
maxUserNameLength: 32
}
10 changes: 6 additions & 4 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ if (process.env.DATABASE_URL === undefined) {
export default defineConfig({
dialect: 'postgresql',
schema: './server/database/schema.ts',
out: './server/database/migrations',
out: './server/database/migrations'

dbCredentials: {
url: process.env.DATABASE_URL
}
// TODO: drizzle-kit doesn't support different drivers at the same time
// https://orm.drizzle.team/kit-docs/upgrade-21#:~:text=For%20postgresql%20dialect%2C%20Drizzle%20will%3A
// dbCredentials: {
// url: process.env.DATABASE_URL
// }
})
3 changes: 2 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default defineNuxtConfig({
},

typescript: {
strict: true
strict: true,
typeCheck: true
},

app: {
Expand Down
159 changes: 159 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"generate": "nuxt generate",
"postinstall": "nuxt prepare",
"preview": "wrangler pages dev",
"db:generate": "npx drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:studio": "npx drizzle-kit studio"
"db:generate": "drizzle-kit generate",
"db:migrate": "tsx ./tools/migrate.ts",
"db:migrate:local": "tsx --env-file=.env ./tools/migrate.ts",
"db:studio": "drizzle-kit studio",
"typecheck": "nuxi typecheck"
},
"dependencies": {
"date-fns": "4.1.0",
Expand All @@ -31,9 +33,11 @@
"consola": "3.2.3",
"drizzle-kit": "0.24.2",
"sass": "1.79.2",
"tsx": "4.19.1",
"typescript": "5.6.2",
"ufo": "1.5.4",
"valibot": "0.42.0",
"vue-tsc": "2.1.6",
"wrangler": "3.78.6",
"ws": "8.18.0"
}
Expand Down
Loading

0 comments on commit 7d64542

Please sign in to comment.