diff options
author | Yorhel <git@yorhel.nl> | 2015-10-21 02:19:15 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2015-10-21 02:28:48 +0200 |
commit | 9cf3eef0e0a7bde10a0e1bb8c94c38b058e5121d (patch) | |
tree | 9cbd3a439316bdfe3946cc80378e4f95a9d6e6db /util/updates | |
parent | 718f4d0258049aa92f229c08d5ec7204dae3ffa6 (diff) |
SQL: Fix editing + func.sql + triggers.sql + autocreate editing funcs
This changes quite a bit to the way the editing functions work. Because
these functions are very repetitive and it's easy to keep things out of
sync, I created a script to generate them automatically. I had to rename
a few function and table names for consistency to make this work.
Since database entries don't have a 'latest' column anymore, and since
the order in which tables are updated doesn't have to be fixed, I
dropped many of the SQL triggers and replaced them with a
edit_committed() function which is called from edit_*_commit() and
checks for stuff to be done.
Don't forget to run 'make' before importing the update script.
Diffstat (limited to 'util/updates')
-rw-r--r-- | util/updates/update_2.25-sqlsplit.sql | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/util/updates/update_2.25-sqlsplit.sql b/util/updates/update_2.25-sqlsplit.sql index eb1ce231..9104972a 100644 --- a/util/updates/update_2.25-sqlsplit.sql +++ b/util/updates/update_2.25-sqlsplit.sql @@ -31,6 +31,15 @@ ALTER TABLE vn_screenshots RENAME TO vn_screenshots_old; ALTER TABLE vn_seiyuu RENAME TO vn_seiyuu_old; ALTER TABLE vn_staff RENAME TO vn_staff_old; +-- XXX: The names of these sequences depend on how the corresponding tables +-- were generated. The names below are the ones in the production database. +ALTER SEQUENCE changes_id_seq RENAME TO changes_id_seq_old; +ALTER SEQUENCE chars_id_seq RENAME TO chars_id_seq_old; +ALTER SEQUENCE producers_id_seq RENAME TO producers_id_seq_old; +ALTER SEQUENCE releases_id_seq RENAME TO releases_id_seq_old; +ALTER SEQUENCE staff_alias_id_seq RENAME TO staff_alias_id_seq_old; +ALTER SEQUENCE staff_id_seq RENAME TO staff_id_seq_old; +ALTER SEQUENCE vn_id_seq RENAME TO vn_id_seq_old; \i util/sql/schema.sql @@ -183,6 +192,14 @@ INSERT INTO vn_staff_hist SELECT vid, aid, role, note FROM vn_staff_old; +SELECT setval('changes_id_seq', nextval('changes_id_seq_old')); +SELECT setval('chars_id_seq', nextval('chars_id_seq_old')); +SELECT setval('producers_id_seq', nextval('producers_id_seq_old')); +SELECT setval('releases_id_seq', nextval('releases_id_seq_old')); +SELECT setval('staff_alias_aid_seq', nextval('staff_alias_id_seq_old')); -- note the change from id to aid +SELECT setval('staff_id_seq', nextval('staff_id_seq_old')); +SELECT setval('vn_id_seq', nextval('vn_id_seq_old')); + -- Dropping all tables with CASCADE causes all foreign key references to and -- from the tables to be dropped as well. This is exactly what we want, so we @@ -214,3 +231,27 @@ DROP TABLE vn_seiyuu_old CASCADE; DROP TABLE vn_staff_old CASCADE; \i util/sql/tableattrs.sql + +DROP FUNCTION edit_revtable(dbentry_type, integer); +DROP FUNCTION edit_vn_init(integer); +DROP FUNCTION edit_vn_commit(); +DROP FUNCTION edit_release_init(integer); +DROP FUNCTION edit_release_commit(); +DROP FUNCTION edit_producer_init(integer); +DROP FUNCTION edit_producer_commit(); +DROP FUNCTION edit_char_init(integer); +DROP FUNCTION edit_char_commit(); +DROP FUNCTION edit_staff_init(integer); +DROP FUNCTION edit_staff_commit(); +DROP FUNCTION release_vncache_update(); +DROP FUNCTION notify_dbdel(); +DROP FUNCTION notify_dbedit(); +DROP FUNCTION notify_listdel(); +DROP FUNCTION update_hidlock(); + +DROP TYPE edit_rettype CASCADE; +CREATE TYPE edit_rettype AS (itemid integer, chid integer, rev integer); + +\i util/sql/func.sql +\i util/sql/editfunc.sql +\i util/sql/triggers.sql |