Skip to content

Commit

Permalink
Merge pull request #175 from codex-team/fix-500-web
Browse files Browse the repository at this point in the history
Fix 500 in editor-tools in API
  • Loading branch information
slaveeks authored Feb 22, 2024
2 parents 6980010 + aee931f commit 6deb4ec
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions migrations/tenant/0017-editor-tools@changing-id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- This migration script alters the data type of the id column to SERIAL
-- Make sure to run this after the initial migration where the table was created

-- Rename the table to avoid conflicts temporarily
ALTER TABLE public.editor_tools RENAME TO temp_editor_tools;

-- Create a new table with the same structure but with id column as SERIAL
CREATE TABLE public.editor_tools (
id SERIAL PRIMARY KEY,
name character varying(255) NOT NULL,
export_name character varying(255) NOT NULL,
source json NOT NULL,
is_default BOOLEAN DEFAULT false
);

-- Copy data from the temporary table to the new table
INSERT INTO public.editor_tools (name, export_name, source, is_default)
SELECT name, export_name, source, is_default FROM temp_editor_tools;

-- Drop the temporary table
DROP TABLE temp_editor_tools;
10 changes: 10 additions & 0 deletions migrations/tenant/0018-editor-tools@add-title.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Add column "title" to "editor_tools" if it doesn't exist
DO $$
BEGIN
IF NOT EXISTS(SELECT *
FROM information_schema.columns
WHERE table_name='editor_tools' AND column_name='title')
THEN
ALTER TABLE "public"."editor_tools" ADD COLUMN "title" VARCHAR(255); -- Adjust the data type and size as needed
END IF;
END $$;
23 changes: 23 additions & 0 deletions migrations/tenant/0019-editor-tools@add-default-tools.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DO $$
BEGIN
-- Add data for Header tool
IF NOT EXISTS(SELECT * FROM public.editor_tools WHERE name = 'header')
THEN
INSERT INTO public.editor_tools (name, title, export_name, source, is_default)
VALUES ('header', 'Heading', 'Header', '{"cdn": "https://cdn.jsdelivr.net/npm/@editorjs/header@2.8.1/dist/header.umd.min.js"}'::json, true);
END IF;

-- Add data for Paragraph tool
IF NOT EXISTS(SELECT * FROM public.editor_tools WHERE name = 'paragraph')
THEN
INSERT INTO public.editor_tools (name, title, export_name, source, is_default)
VALUES ('paragraph', 'Paragraph', 'Paragraph', '{"cdn": "https://cdn.jsdelivr.net/npm/@editorjs/paragraph@2.11.3/dist/paragraph.umd.min.js"}'::json, true);
END IF;

-- Add data for List tool
IF NOT EXISTS(SELECT * FROM public.editor_tools WHERE name = 'list')
THEN
INSERT INTO public.editor_tools (name, title, export_name, source, is_default)
VALUES ('list', 'List', 'List', '{"cdn": "https://cdn.jsdelivr.net/npm/@editorjs/list@1.9.0/dist/list.umd.min.js"}'::json, true);
END IF;
END $$;

0 comments on commit 6deb4ec

Please sign in to comment.