From 75b9c2f45b4819ba2a388559dd0a0bd537bd628e Mon Sep 17 00:00:00 2001 From: Matt Kilgore Date: Thu, 26 Dec 2024 18:36:28 +0000 Subject: [PATCH] fix: missing migration --- backend/go.sum | 8 +++ .../migrations/20241226183416_sync_childs.sql | 24 +++++++ .../data/migrations/migrations/atlas.sum | 3 +- docs/docs/api/openapi-2.0.json | 69 ++++++++++++------- frontend/lib/api/types/data-contracts.ts | 2 + 5 files changed, 82 insertions(+), 24 deletions(-) create mode 100644 backend/internal/data/migrations/migrations/20241226183416_sync_childs.sql diff --git a/backend/go.sum b/backend/go.sum index d9bc858d..ae832532 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -110,6 +110,8 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= +github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM= github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= @@ -119,6 +121,8 @@ github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJm github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/olahol/melody v1.2.1 h1:xdwRkzHxf+B0w4TKbGpUSSkV516ZucQZJIWLztOWICQ= github.com/olahol/melody v1.2.1/go.mod h1:GgkTl6Y7yWj/HtfD48Q5vLKPVoZOH+Qqgfa7CvJgJM4= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo/v2 v2.9.2 h1:BA2GMJOtfGAfagzYtrAlufIP0lq6QERkFmHLMLPwFSU= github.com/onsi/ginkgo/v2 v2.9.2/go.mod h1:WHcJJG2dIlcCqVfBAwUCrJxSPFb6v4azBwgxeMeDuts= github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= @@ -136,6 +140,10 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= diff --git a/backend/internal/data/migrations/migrations/20241226183416_sync_childs.sql b/backend/internal/data/migrations/migrations/20241226183416_sync_childs.sql new file mode 100644 index 00000000..0a9b17c8 --- /dev/null +++ b/backend/internal/data/migrations/migrations/20241226183416_sync_childs.sql @@ -0,0 +1,24 @@ +-- Disable the enforcement of foreign-keys constraints +PRAGMA foreign_keys = off; +-- Create "new_items" table +CREATE TABLE `new_items` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `name` text NOT NULL, `description` text NULL, `import_ref` text NULL, `notes` text NULL, `quantity` integer NOT NULL DEFAULT (1), `insured` bool NOT NULL DEFAULT (false), `archived` bool NOT NULL DEFAULT (false), `asset_id` integer NOT NULL DEFAULT (0), `sync_child_items_locations` bool NOT NULL DEFAULT (false), `serial_number` text NULL, `model_number` text NULL, `manufacturer` text NULL, `lifetime_warranty` bool NOT NULL DEFAULT (false), `warranty_expires` datetime NULL, `warranty_details` text NULL, `purchase_time` datetime NULL, `purchase_from` text NULL, `purchase_price` real NOT NULL DEFAULT (0), `sold_time` datetime NULL, `sold_to` text NULL, `sold_price` real NOT NULL DEFAULT (0), `sold_notes` text NULL, `group_items` uuid NOT NULL, `item_children` uuid NULL, `location_items` uuid NULL, PRIMARY KEY (`id`), CONSTRAINT `items_groups_items` FOREIGN KEY (`group_items`) REFERENCES `groups` (`id`) ON DELETE CASCADE, CONSTRAINT `items_items_children` FOREIGN KEY (`item_children`) REFERENCES `items` (`id`) ON DELETE SET NULL, CONSTRAINT `items_locations_items` FOREIGN KEY (`location_items`) REFERENCES `locations` (`id`) ON DELETE CASCADE); +-- Copy rows from old table "items" to new temporary table "new_items" +INSERT INTO `new_items` (`id`, `created_at`, `updated_at`, `name`, `description`, `import_ref`, `notes`, `quantity`, `insured`, `archived`, `asset_id`, `serial_number`, `model_number`, `manufacturer`, `lifetime_warranty`, `warranty_expires`, `warranty_details`, `purchase_time`, `purchase_from`, `purchase_price`, `sold_time`, `sold_to`, `sold_price`, `sold_notes`, `group_items`, `item_children`, `location_items`) SELECT `id`, `created_at`, `updated_at`, `name`, `description`, `import_ref`, `notes`, `quantity`, `insured`, `archived`, `asset_id`, `serial_number`, `model_number`, `manufacturer`, `lifetime_warranty`, `warranty_expires`, `warranty_details`, `purchase_time`, `purchase_from`, `purchase_price`, `sold_time`, `sold_to`, `sold_price`, `sold_notes`, `group_items`, `item_children`, `location_items` FROM `items`; +-- Drop "items" table after copying rows +DROP TABLE `items`; +-- Rename temporary table "new_items" to "items" +ALTER TABLE `new_items` RENAME TO `items`; +-- Create index "item_name" to table: "items" +CREATE INDEX `item_name` ON `items` (`name`); +-- Create index "item_manufacturer" to table: "items" +CREATE INDEX `item_manufacturer` ON `items` (`manufacturer`); +-- Create index "item_model_number" to table: "items" +CREATE INDEX `item_model_number` ON `items` (`model_number`); +-- Create index "item_serial_number" to table: "items" +CREATE INDEX `item_serial_number` ON `items` (`serial_number`); +-- Create index "item_archived" to table: "items" +CREATE INDEX `item_archived` ON `items` (`archived`); +-- Create index "item_asset_id" to table: "items" +CREATE INDEX `item_asset_id` ON `items` (`asset_id`); +-- Enable back the enforcement of foreign-keys constraints +PRAGMA foreign_keys = on; diff --git a/backend/internal/data/migrations/migrations/atlas.sum b/backend/internal/data/migrations/migrations/atlas.sum index e8d99a61..70937f20 100644 --- a/backend/internal/data/migrations/migrations/atlas.sum +++ b/backend/internal/data/migrations/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:sjJCTAqc9FG8BKBIzh5ZynYD/Ilz6vnLqM4XX83WQ4M= +h1:vfyg10T5DT60HhDoHrD7YGmXlGVTOogzumhvxIx4uqw= 20220929052825_init.sql h1:ZlCqm1wzjDmofeAcSX3jE4h4VcdTNGpRg2eabztDy9Q= 20221001210956_group_invitations.sql h1:YQKJFtE39wFOcRNbZQ/d+ZlHwrcfcsZlcv/pLEYdpjw= 20221009173029_add_user_roles.sql h1:vWmzAfgEWQeGk0Vn70zfVPCcfEZth3E0JcvyKTjpYyU= @@ -13,3 +13,4 @@ h1:sjJCTAqc9FG8BKBIzh5ZynYD/Ilz6vnLqM4XX83WQ4M= 20230305065819_add_notifier_types.sql h1:r5xrgCKYQ2o9byBqYeAX1zdp94BLdaxf4vq9OmGHNl0= 20230305071524_add_group_id_to_notifiers.sql h1:xDShqbyClcFhvJbwclOHdczgXbdffkxXNWjV61hL/t4= 20231006213457_add_primary_attachment_flag.sql h1:J4tMSJQFa7vaj0jpnh8YKTssdyIjRyq6RXDXZIzDDu4= +20241226183416_sync_childs.sql h1:RWK0tyu8Wj5ypRceCZWCTEXJQGCjWQMhCUBHUBXGseI= diff --git a/docs/docs/api/openapi-2.0.json b/docs/docs/api/openapi-2.0.json index 4b84c8ed..3077c6cc 100644 --- a/docs/docs/api/openapi-2.0.json +++ b/docs/docs/api/openapi-2.0.json @@ -559,6 +559,9 @@ "Bearer": [] } ], + "consumes": [ + "multipart/form-data" + ], "produces": [ "application/json" ], @@ -730,6 +733,9 @@ "Bearer": [] } ], + "consumes": [ + "multipart/form-data" + ], "produces": [ "application/json" ], @@ -914,6 +920,13 @@ ], "summary": "Get Maintenance Log", "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, { "enum": [ "scheduled", @@ -956,6 +969,13 @@ ], "summary": "Create Maintenance Entry", "parameters": [ + { + "type": "string", + "description": "Item ID", + "name": "id", + "in": "path", + "required": true + }, { "description": "Entry Data", "name": "payload", @@ -1427,6 +1447,13 @@ ], "summary": "Update Maintenance Entry", "parameters": [ + { + "type": "string", + "description": "Maintenance ID", + "name": "id", + "in": "path", + "required": true + }, { "description": "Entry Data", "name": "payload", @@ -1459,6 +1486,15 @@ "Maintenance" ], "summary": "Delete Maintenance Entry", + "parameters": [ + { + "type": "string", + "description": "Maintenance ID", + "name": "id", + "in": "path", + "required": true + } + ], "responses": { "204": { "description": "No Content" @@ -1541,13 +1577,6 @@ ], "summary": "Test Notifier", "parameters": [ - { - "type": "string", - "description": "Notifier ID", - "name": "id", - "in": "path", - "required": true - }, { "type": "string", "description": "URL", @@ -1745,20 +1774,6 @@ ], "summary": "User Login", "parameters": [ - { - "type": "string", - "example": "admin@admin.com", - "description": "string", - "name": "username", - "in": "formData" - }, - { - "type": "string", - "example": "admin", - "description": "string", - "name": "password", - "in": "formData" - }, { "description": "Login Data", "name": "payload", @@ -2235,6 +2250,9 @@ "soldTo": { "type": "string" }, + "syncChildItemsLocations": { + "type": "boolean" + }, "updatedAt": { "type": "string" }, @@ -2437,6 +2455,9 @@ "type": "string", "maxLength": 255 }, + "syncChildItemsLocations": { + "type": "boolean" + }, "warrantyDetails": { "type": "string" }, @@ -3043,13 +3064,15 @@ "type": "object", "properties": { "password": { - "type": "string" + "type": "string", + "example": "admin" }, "stayLoggedIn": { "type": "boolean" }, "username": { - "type": "string" + "type": "string", + "example": "admin@admin.com" } } }, diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index bac152df..b4ee1d5a 100644 --- a/frontend/lib/api/types/data-contracts.ts +++ b/frontend/lib/api/types/data-contracts.ts @@ -444,8 +444,10 @@ export interface ItemAttachmentToken { } export interface LoginForm { + /** @example "admin" */ password: string; stayLoggedIn: boolean; + /** @example "admin@admin.com" */ username: string; }