mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 02:57:14 +02:00
✨ Many improvements to the database layer.
- Proper handling of referenced tables deletion. - Proper handling of storage referenced tables deletion. - Remove of obsolete tables and triggers.
This commit is contained in:
parent
d32cacf1da
commit
16469daff3
8 changed files with 72 additions and 7 deletions
|
@ -122,6 +122,15 @@
|
||||||
|
|
||||||
{:name "0036-mod-storage-referenced-tables"
|
{:name "0036-mod-storage-referenced-tables"
|
||||||
:fn (mg/resource "app/migrations/sql/0036-mod-storage-referenced-tables.sql")}
|
:fn (mg/resource "app/migrations/sql/0036-mod-storage-referenced-tables.sql")}
|
||||||
|
|
||||||
|
{:name "0037-del-obsolete-triggers"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0037-del-obsolete-triggers.sql")}
|
||||||
|
|
||||||
|
{:name "0038-add-storage-on-delete-triggers"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0038-add-storage-on-delete-triggers.sql")}
|
||||||
|
|
||||||
|
{:name "0039-fix-some-on-delete-triggers"
|
||||||
|
:fn (mg/resource "app/migrations/sql/0039-fix-some-on-delete-triggers.sql")}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -106,8 +106,6 @@ CREATE TRIGGER file_image__on_delete__tgr
|
||||||
AFTER DELETE ON file_image
|
AFTER DELETE ON file_image
|
||||||
FOR EACH ROW EXECUTE PROCEDURE handle_delete();
|
FOR EACH ROW EXECUTE PROCEDURE handle_delete();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE page (
|
CREATE TABLE page (
|
||||||
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
|
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
file_id uuid NOT NULL REFERENCES file(id) ON DELETE CASCADE,
|
file_id uuid NOT NULL REFERENCES file(id) ON DELETE CASCADE,
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
-- Complete migration consists of:
|
|
||||||
-- - Move all file_media_objects and file_media_thumbnail to new storage.
|
|
||||||
-- - Replace the relative paths to the storage id's on all files/pages.
|
|
||||||
-- - Adapt frontend code to properly resolve url using the ids instead of paths.
|
|
||||||
|
|
||||||
-- Profile
|
-- Profile
|
||||||
ALTER TABLE profile ADD COLUMN photo_id uuid NULL REFERENCES storage_object(id) ON DELETE SET NULL;
|
ALTER TABLE profile ADD COLUMN photo_id uuid NULL REFERENCES storage_object(id) ON DELETE SET NULL;
|
||||||
CREATE INDEX profile__photo_id__idx ON profile(photo_id);
|
CREATE INDEX profile__photo_id__idx ON profile(photo_id);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
DROP FUNCTION update_modified_at () CASCADE;
|
||||||
|
DROP FUNCTION handle_delete ( ) CASCADE;
|
||||||
|
DROP TABLE pending_to_delete;
|
|
@ -0,0 +1,50 @@
|
||||||
|
CREATE FUNCTION on_delete_profile()
|
||||||
|
RETURNS TRIGGER AS $func$
|
||||||
|
BEGIN
|
||||||
|
UPDATE storage_object
|
||||||
|
SET deleted_at = now()
|
||||||
|
WHERE id = OLD.photo_id;
|
||||||
|
|
||||||
|
RETURN OLD;
|
||||||
|
END;
|
||||||
|
$func$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE FUNCTION on_delete_team()
|
||||||
|
RETURNS TRIGGER AS $func$
|
||||||
|
BEGIN
|
||||||
|
UPDATE storage_object
|
||||||
|
SET deleted_at = now()
|
||||||
|
WHERE id = OLD.photo_id;
|
||||||
|
|
||||||
|
RETURN OLD;
|
||||||
|
END;
|
||||||
|
$func$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE FUNCTION on_delete_file_media_object()
|
||||||
|
RETURNS TRIGGER AS $func$
|
||||||
|
BEGIN
|
||||||
|
UPDATE storage_object
|
||||||
|
SET deleted_at = now()
|
||||||
|
WHERE id = OLD.media_id;
|
||||||
|
|
||||||
|
IF OLD.thumbnail_id IS NOT NULL THEN
|
||||||
|
UPDATE storage_object
|
||||||
|
SET deleted_at = now()
|
||||||
|
WHERE id = OLD.thumbnail_id;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN OLD;
|
||||||
|
END;
|
||||||
|
$func$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE TRIGGER profile__on_delete__tgr
|
||||||
|
AFTER DELETE ON profile
|
||||||
|
FOR EACH ROW EXECUTE PROCEDURE on_delete_profile();
|
||||||
|
|
||||||
|
CREATE TRIGGER team__on_delete__tgr
|
||||||
|
AFTER DELETE ON team
|
||||||
|
FOR EACH ROW EXECUTE PROCEDURE on_delete_team();
|
||||||
|
|
||||||
|
CREATE TRIGGER file_media_object__on_delete__tgr
|
||||||
|
AFTER DELETE ON file_media_object
|
||||||
|
FOR EACH ROW EXECUTE PROCEDURE on_delete_file_media_object();
|
|
@ -0,0 +1,9 @@
|
||||||
|
ALTER TABLE file_library_rel
|
||||||
|
DROP CONSTRAINT file_library_rel_library_file_id_fkey,
|
||||||
|
ADD CONSTRAINT file_library_rel_library_file_id_fkey
|
||||||
|
FOREIGN KEY (library_file_id) REFERENCES file(id) ON DELETE CASCADE;
|
||||||
|
|
||||||
|
ALTER TABLE team_profile_rel
|
||||||
|
DROP CONSTRAINT team_profile_rel_profile_id_fkey,
|
||||||
|
ADD CONSTRAINT team_profile_rel_profile_id_fkey
|
||||||
|
FOREIGN KEY (profile_id) REFERENCES profile(id) ON DELETE CASCADE;
|
|
@ -141,6 +141,7 @@
|
||||||
(db/delete! conn :team {:id id})
|
(db/delete! conn :team {:id id})
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
|
|
||||||
;; --- Mutation: Tean Update Role
|
;; --- Mutation: Tean Update Role
|
||||||
|
|
||||||
(declare retrieve-team-member)
|
(declare retrieve-team-member)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue