Browse Source

Added history to nodes

sferot 10 years ago
parent
commit
c036f1695e
2 changed files with 104 additions and 0 deletions
  1. 62 0
      .gitignore
  2. 42 0
      doc/database/pod-upgrade-0.2.0_to_0.3.0.sql

+ 62 - 0
.gitignore View File

@@ -0,0 +1,62 @@
1
+# Byte-compiled / optimized / DLL files
2
+__pycache__/
3
+*.py[cod]
4
+
5
+# C extensions
6
+*.so
7
+
8
+# Distribution / packaging
9
+.Python
10
+env/
11
+bin/
12
+build/
13
+develop-eggs/
14
+dist/
15
+eggs/
16
+lib/
17
+lib64/
18
+parts/
19
+sdist/
20
+var/
21
+*.egg-info/
22
+.installed.cfg
23
+*.egg
24
+
25
+# Installer logs
26
+pip-log.txt
27
+pip-delete-this-directory.txt
28
+
29
+# Unit test / coverage reports
30
+htmlcov/
31
+.tox/
32
+.coverage
33
+.cache
34
+nosetests.xml
35
+coverage.xml
36
+
37
+# Translations
38
+*.mo
39
+
40
+# Mr Developer
41
+.mr.developer.cfg
42
+.project
43
+.pydevproject
44
+
45
+# Rope
46
+.ropeproject
47
+
48
+# Django stuff:
49
+*.log
50
+*.pot
51
+
52
+# Sphinx documentation
53
+docs/_build/
54
+
55
+# Vim
56
+*.swp
57
+
58
+# Virtualenv
59
+tg2env/
60
+
61
+# cache
62
+pboard/data/

+ 42 - 0
doc/database/pod-upgrade-0.2.0_to_0.3.0.sql View File

@@ -0,0 +1,42 @@
1
+-- move table
2
+ALTER TABLE pod_nodes RENAME TO pod_nodes_history;
3
+
4
+-- add uuid index
5
+-- drop primary key
6
+-- new primary key
7
+CREATE SEQUENCE pod_nodes_version_id_sequence;
8
+ALTER TABLE pod_nodes_history
9
+    DROP CONSTRAINT pod_nodes_pk CASCADE,
10
+    ADD COLUMN version_id INTEGER PRIMARY KEY DEFAULT nextval('pod_nodes_version_id_sequence');
11
+
12
+-- create view
13
+CREATE OR REPLACE VIEW pod_nodes AS
14
+    SELECT DISTINCT ON (node_id) 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
18
+    FROM pod_nodes_history
19
+    ORDER BY node_id, updated_at DESC;
20
+
21
+CREATE OR REPLACE RULE pod_insert_new_node AS ON INSERT
22
+TO pod_nodes
23
+DO INSTEAD INSERT INTO pod_nodes_history (node_id, parent_id, node_order, node_type, created_at, updated_at, 
24
+       data_label, data_content, data_datetime, node_status, data_reminder_datetime, 
25
+       data_file_name, data_file_content, data_file_mime_type, parent_tree_path, 
26
+       node_depth, owner_id, version_id) 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'))
27
+RETURNING node_id, parent_id, node_order, node_type, created_at, updated_at, 
28
+       data_label, data_content, data_datetime, node_status, data_reminder_datetime, 
29
+       data_file_name, data_file_content, data_file_mime_type, parent_tree_path, 
30
+       node_depth, owner_id;
31
+
32
+CREATE OR REPLACE FUNCTION pod_update_node() RETURNS trigger AS $$
33
+BEGIN
34
+INSERT INTO pod_nodes_history (node_id, parent_id, node_order, node_type, created_at, updated_at, 
35
+       data_label, data_content, data_datetime, node_status, data_reminder_datetime, 
36
+       data_file_name, data_file_content, data_file_mime_type, parent_tree_path, 
37
+       node_depth, owner_id, version_id) 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'));
38
+return new;
39
+END;
40
+$$ LANGUAGE plpgsql;
41
+
42
+CREATE TRIGGER pod_update_node_tg INSTEAD OF UPDATE ON pod_nodes FOR EACH ROW EXECUTE PROCEDURE pod_update_node();