From 151ac0602afb6f57541364367f9dcf7a66da47ea Mon Sep 17 00:00:00 2001 From: Sonny Date: Tue, 21 Jan 2025 18:14:43 +0100 Subject: [PATCH] fix: "cannot remove collection" related to unused stuff --- app/collections/models/collection.ts | 3 --- .../validators/create_collection_validator.ts | 1 - .../validators/update_collection_validator.ts | 1 - ...78982886_drop_next_id_collections_table.ts | 21 +++++++++++++++++++ database/seeders/collection_seeder.ts | 1 - inertia/components/form/form_collection.tsx | 3 +-- inertia/pages/collections/edit.tsx | 1 - inertia/types/app.ts | 1 - 8 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 database/migrations/1737478982886_drop_next_id_collections_table.ts diff --git a/app/collections/models/collection.ts b/app/collections/models/collection.ts index 0045751..4865a79 100644 --- a/app/collections/models/collection.ts +++ b/app/collections/models/collection.ts @@ -15,9 +15,6 @@ export default class Collection extends AppBaseModel { @column() declare visibility: Visibility; - @column() - declare nextId: number; - @column() declare authorId: number; diff --git a/app/collections/validators/create_collection_validator.ts b/app/collections/validators/create_collection_validator.ts index 0432eb8..97f5e3c 100644 --- a/app/collections/validators/create_collection_validator.ts +++ b/app/collections/validators/create_collection_validator.ts @@ -6,7 +6,6 @@ export const createCollectionValidator = vine.compile( name: vine.string().trim().minLength(1).maxLength(254), description: vine.string().trim().maxLength(254).nullable(), visibility: vine.enum(Visibility), - nextId: vine.number().optional(), }) ); diff --git a/app/collections/validators/update_collection_validator.ts b/app/collections/validators/update_collection_validator.ts index 36f8963..0ab53a4 100644 --- a/app/collections/validators/update_collection_validator.ts +++ b/app/collections/validators/update_collection_validator.ts @@ -7,7 +7,6 @@ export const updateCollectionValidator = vine.compile( name: vine.string().trim().minLength(1).maxLength(254), description: vine.string().trim().maxLength(254).nullable(), visibility: vine.enum(Visibility), - nextId: vine.number().optional(), params, }) diff --git a/database/migrations/1737478982886_drop_next_id_collections_table.ts b/database/migrations/1737478982886_drop_next_id_collections_table.ts new file mode 100644 index 0000000..47dca78 --- /dev/null +++ b/database/migrations/1737478982886_drop_next_id_collections_table.ts @@ -0,0 +1,21 @@ +import { BaseSchema } from '@adonisjs/lucid/schema'; + +export default class extends BaseSchema { + protected tableName = 'collections'; + + async up() { + this.schema.alterTable('collections', (table) => { + table.dropColumn('next_id'); + }); + } + + async down() { + this.schema.alterTable('collections', (table) => { + table + .integer('next_id') + .references('id') + .inTable('collections') + .defaultTo(null); + }); + } +} diff --git a/database/seeders/collection_seeder.ts b/database/seeders/collection_seeder.ts index 7e6f2cf..3359e58 100644 --- a/database/seeders/collection_seeder.ts +++ b/database/seeders/collection_seeder.ts @@ -34,7 +34,6 @@ function createRandomCollection(userIds: User['id'][]) { name: faker.string.alphanumeric({ length: { min: 5, max: 25 } }), description: faker.string.alphanumeric({ length: { min: 0, max: 254 } }), visibility: Visibility.PRIVATE, - nextId: collectionId + 1, authorId, }; } diff --git a/inertia/components/form/form_collection.tsx b/inertia/components/form/form_collection.tsx index 1460a83..8637495 100644 --- a/inertia/components/form/form_collection.tsx +++ b/inertia/components/form/form_collection.tsx @@ -3,13 +3,12 @@ import { FormEvent } from 'react'; import { useTranslation } from 'react-i18next'; import BackToDashboard from '~/components/common/navigation/back_to_dashboard'; import { FormLayout, FormLayoutProps } from '~/layouts/form_layout'; -import { Collection, Visibility } from '~/types/app'; +import { Visibility } from '~/types/app'; export type FormCollectionData = { name: string; description: string | null; visibility: Visibility; - nextId?: Collection['id']; }; interface FormCollectionProps extends FormLayoutProps { diff --git a/inertia/pages/collections/edit.tsx b/inertia/pages/collections/edit.tsx index bb23008..ce5dbc3 100644 --- a/inertia/pages/collections/edit.tsx +++ b/inertia/pages/collections/edit.tsx @@ -18,7 +18,6 @@ export default function EditCollectionPage({ name: collection.name, description: collection.description, visibility: collection.visibility, - nextId: collection.nextId, }); const canSubmit = useMemo(() => { const trimmedName = data.name.trim(); diff --git a/inertia/types/app.ts b/inertia/types/app.ts index 8499b78..80ec57f 100644 --- a/inertia/types/app.ts +++ b/inertia/types/app.ts @@ -49,7 +49,6 @@ export type Collection = CommonBase & { name: string; description: string | null; visibility: Visibility; - nextId: number; authorId: number; };