2023-06-29 19:26:03 +03:00
|
|
|
BEGIN;
|
|
|
|
|
|
|
|
-- Add the file_sha1 column if it doesn't exist
|
|
|
|
ALTER TABLE IF EXISTS brains_vectors
|
|
|
|
ADD COLUMN IF NOT EXISTS file_sha1 TEXT;
|
|
|
|
|
|
|
|
-- Update the file_sha1 column with values from vectors.metadata
|
|
|
|
UPDATE brains_vectors
|
|
|
|
SET file_sha1 = subquery.file_sha1
|
|
|
|
FROM (
|
|
|
|
SELECT vectors.id, vectors.metadata->>'file_sha1' AS file_sha1
|
|
|
|
FROM vectors
|
|
|
|
) AS subquery
|
|
|
|
WHERE brains_vectors.vector_id = subquery.id
|
|
|
|
AND (brains_vectors.file_sha1 IS NULL OR brains_vectors.file_sha1 = '');
|
|
|
|
|
2023-07-03 15:41:33 +03:00
|
|
|
|
2023-07-03 12:11:29 +03:00
|
|
|
INSERT INTO migrations (name)
|
2023-07-03 15:41:33 +03:00
|
|
|
SELECT '20230629143400_add_file_sha1_brains_vectors'
|
2023-07-03 12:11:29 +03:00
|
|
|
WHERE NOT EXISTS (
|
|
|
|
SELECT 1 FROM migrations WHERE name = '20230629143400_add_file_sha1_brains_vectors'
|
|
|
|
);
|
|
|
|
|
2023-06-29 19:26:03 +03:00
|
|
|
COMMIT;
|