-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds all system_models types on migration
- Loading branch information
1 parent
4f3a656
commit 4fc4e22
Showing
6 changed files
with
916 additions
and
44 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
services/backend/src/db/migrations/0001_migrate_system_models.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- Custom SQL migration file, put your code below! -- | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'system_models_enum') THEN | ||
CREATE TYPE system_models_enum AS ENUM ( | ||
'VisioPointer', | ||
'VisioCompact', | ||
'VisioLine', | ||
'SmartInspector', | ||
'360 Inspector', | ||
'VisioOne', | ||
'IML-Inspector' | ||
); | ||
END IF; | ||
END $$; | ||
|
||
-- Function to generate random string of specified length | ||
CREATE OR REPLACE FUNCTION generate_random_string(length INTEGER) RETURNS TEXT AS $$ | ||
DECLARE | ||
chars TEXT := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | ||
result TEXT := ''; | ||
i INTEGER := 0; | ||
BEGIN | ||
FOR i IN 1..length LOOP | ||
result := result || substr(chars, floor(random() * length(chars) + 1)::INTEGER, 1); | ||
END LOOP; | ||
RETURN result; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- Insert the system models | ||
INSERT INTO system_models (id, name) | ||
VALUES | ||
(generate_random_string(12), 'VisioPointer'::system_models_enum), | ||
(generate_random_string(12), 'VisioCompact'::system_models_enum), | ||
(generate_random_string(12), 'VisioLine'::system_models_enum), | ||
(generate_random_string(12), 'SmartInspector'::system_models_enum), | ||
(generate_random_string(12), '360 Inspector'::system_models_enum), | ||
(generate_random_string(12), 'VisioOne'::system_models_enum), | ||
(generate_random_string(12), 'IML-Inspector'::system_models_enum) | ||
ON CONFLICT (id) DO NOTHING; | ||
|
||
-- Clean up the function | ||
DROP FUNCTION IF EXISTS generate_random_string(INTEGER); |
Oops, something went wrong.