mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 17:43:03 +03:00
31c1802084
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
34 lines
1.2 KiB
SQL
34 lines
1.2 KiB
SQL
DO $$
|
|
BEGIN
|
|
-- Add 'name' column if it does not exist
|
|
IF NOT EXISTS (SELECT FROM pg_attribute WHERE attrelid = 'api_keys'::regclass AND attname = 'name') THEN
|
|
ALTER TABLE api_keys ADD COLUMN name TEXT DEFAULT 'API_KEY';
|
|
END IF;
|
|
|
|
-- Add 'days' column if it does not exist
|
|
IF NOT EXISTS (SELECT FROM pg_attribute WHERE attrelid = 'api_keys'::regclass AND attname = 'days') THEN
|
|
ALTER TABLE api_keys ADD COLUMN days INT DEFAULT 30;
|
|
END IF;
|
|
|
|
-- Add 'only_chat' column if it does not exist
|
|
IF NOT EXISTS (SELECT FROM pg_attribute WHERE attrelid = 'api_keys'::regclass AND attname = 'only_chat') THEN
|
|
ALTER TABLE api_keys ADD COLUMN only_chat BOOLEAN DEFAULT false;
|
|
END IF;
|
|
|
|
-- Optionally, update default values for existing rows if necessary
|
|
-- UPDATE api_keys SET name = 'API_KEY' WHERE name IS NULL;
|
|
-- UPDATE api_keys SET days = 30 WHERE days IS NULL;
|
|
-- UPDATE api_keys SET only_chat = false WHERE only_chat IS NULL;
|
|
|
|
END $$;
|
|
|
|
|
|
-- Update migrations table
|
|
INSERT INTO migrations (name)
|
|
SELECT '20231203173900_new_api_key_format'
|
|
WHERE NOT EXISTS (
|
|
SELECT 1 FROM migrations WHERE name = '20231203173900_new_api_key_format'
|
|
);
|
|
|
|
COMMIT;
|