pod-upgrade-0.3.0_to_0.4.0.sql 2.8KB

123456789101112131415161718192021222324252627282930313233343536
  1. ALTER TABLE pod_nodes_history ADD COLUMN is_shared boolean NOT NULL DEFAULT False;
  2. ALTER TABLE pod_nodes_history ADD COLUMN is_public boolean NOT NULL DEFAULT False;
  3. ALTER TABLE pod_nodes_history ADD COLUMN public_url_key character varying(1024);
  4. -- create view
  5. CREATE OR REPLACE VIEW pod_nodes AS
  6. SELECT DISTINCT ON (node_id) node_id, parent_id, node_order, node_type, created_at, updated_at,
  7. data_label, data_content, data_datetime, node_status, data_reminder_datetime,
  8. data_file_name, data_file_content, data_file_mime_type, parent_tree_path,
  9. node_depth, owner_id, is_shared, is_public, public_url_key
  10. FROM pod_nodes_history
  11. ORDER BY node_id, updated_at DESC;
  12. CREATE OR REPLACE RULE pod_insert_new_node AS ON INSERT
  13. TO pod_nodes
  14. DO INSTEAD INSERT INTO pod_nodes_history (node_id, parent_id, node_order, node_type, created_at, updated_at,
  15. data_label, data_content, data_datetime, node_status, data_reminder_datetime,
  16. data_file_name, data_file_content, data_file_mime_type, parent_tree_path,
  17. node_depth, owner_id, version_id, is_shared, is_public, public_url_key) VALUES (nextval('pod_nodes__node_id__sequence'), NEW.parent_id, NEW.node_order, NEW.node_type, NEW.created_at, NEW.updated_at, NEW.data_label, NEW.data_content, NEW.data_datetime, NEW.node_status, NEW.data_reminder_datetime, NEW.data_file_name, NEW.data_file_content, NEW.data_file_mime_type, NEW.parent_tree_path, NEW.node_depth, NEW.owner_id, nextval('pod_nodes_version_id_sequence'), NEW.is_shared, NEW.is_public, NEW.public_url_key)
  18. RETURNING node_id, parent_id, node_order, node_type, created_at, updated_at,
  19. data_label, data_content, data_datetime, node_status, data_reminder_datetime,
  20. data_file_name, data_file_content, data_file_mime_type, parent_tree_path,
  21. node_depth, owner_id, is_shared, is_public, public_url_key;
  22. CREATE OR REPLACE FUNCTION pod_update_node() RETURNS trigger AS $$
  23. BEGIN
  24. INSERT INTO pod_nodes_history (node_id, parent_id, node_order, node_type, created_at, updated_at,
  25. data_label, data_content, data_datetime, node_status, data_reminder_datetime,
  26. data_file_name, data_file_content, data_file_mime_type, parent_tree_path,
  27. node_depth, owner_id, version_id, is_shared, is_public, public_url_key) VALUES (NEW.node_id, NEW.parent_id, NEW.node_order, NEW.node_type, NEW.created_at, NEW.updated_at, NEW.data_label, NEW.data_content, NEW.data_datetime, NEW.node_status, NEW.data_reminder_datetime, NEW.data_file_name, NEW.data_file_content, NEW.data_file_mime_type, NEW.parent_tree_path, NEW.node_depth, NEW.owner_id, nextval('pod_nodes_version_id_sequence'), NEW.is_shared, NEW.is_public, NEW.public_url_key);
  28. return new;
  29. END;
  30. $$ LANGUAGE plpgsql;
  31. CREATE TRIGGER pod_update_node_tg INSTEAD OF UPDATE ON pod_nodes FOR EACH ROW EXECUTE PROCEDURE pod_update_node();