summaryrefslogtreecommitdiff
path: root/sql/Pg-upgrade-2.6.17-2.6.18.sql
blob: a0ad36d5509d02d30226675dc15503904595dc53 (plain)
  1. -- linuxpoet:
  2. -- adding primary key to acc_trans
  3. -- We are using standard postgresql names for the sequence for consistency as we move forward
  4. -- Do everything in a transaction in case it blows up
  5. BEGIN;
  6. LOCK acc_trans in EXCLUSIVE mode;
  7. ALTER TABLE acc_trans ADD COLUMN entry_id bigint;
  8. CREATE SEQUENCE acctrans_entry_id_seq;
  9. ALTER TABLE acc_trans ALTER COLUMN entry_id SET DEFAULT nextval('acctrans_entry_id_seq');
  10. UPDATE acc_trans SET entry_id = nextval('acctrans_entry_id_seq');
  11. ALTER TABLE acc_trans ADD PRIMARY key (entry_id);
  12. -- Start changing floats
  13. ALTER TABLE acc_trans ALTER COLUMN amount TYPE numeric(10,2);
  14. -- This may break someone if they for some reason have an actual float type in the qty column
  15. ALTER TABLE invoice ALTER COLUMN qty TYPE numeric;
  16. ALTER TABLE invoice ALTER COLUMN allocated TYPE numeric;
  17. ALTER TABLE invoice ALTER COLUMN sellprice TYPE numeric(10,2);
  18. ALTER TABLE invoice ALTER COLUMN fxsellprice TYPE numeric(10,2);
  19. ALTER TABLE customer ALTER COLUMN discount TYPE numeric;
  20. ALTER TABLE customer ALTER COLUMN creditlimit TYPE numeric(10,2);
  21. ALTER TABLE parts ALTER COLUMN listprice TYPE numeric(10,2);
  22. ALTER TABLE parts ALTER COLUMN sellprice TYPE numeric(10,2);
  23. ALTER TABLE parts ALTER COLUMN lastcost TYPE numeric(10,2);
  24. ALTER TABLE parts ALTER COLUMN weight TYPE numeric;
  25. ALTER TABLE parts ALTER COLUMN onhand TYPE numeric;
  26. ALTER TABLE parts ALTER COLUMN avgcost TYPE numeric(10,2);
  27. ALTER TABLE assembly ALTER COLUMN qty TYPE numeric;
  28. ALTER TABLE ar ALTER COLUMN amount TYPE numeric(10,2);
  29. ALTER TABLE ar ALTER COLUMN netamount TYPE numeric(10,2);
  30. ALTER TABLE ar ALTER COLUMN paid TYPE numeric(10,2);
  31. ALTER TABLE ap ALTER COLUMN amount TYPE numeric(10,2);
  32. ALTER TABLE ap ALTER COLUMN netamount TYPE numeric(10,2);
  33. ALTER TABLE ap ALTER COLUMN paid TYPE numeric(10,2);
  34. ALTER TABLE tax ALTER COLUMN rate TYPE numeric;
  35. ALTER TABLE oe ALTER COLUMN amount TYPE numeric(10,2);
  36. ALTER TABLE oe ALTER COLUMN netamount TYPE numeric(10,2);
  37. ALTER TABLE orderitems ALTER COLUMN qty TYPE numeric;
  38. ALTER TABLE orderitems ALTER COLUMN sellprice TYPE numeric(10,2);
  39. ALTER TABLE orderitems ALTER COLUMN discount TYPE numeric;
  40. ALTER TABLE orderitems ALTER COLUMN ship TYPE numeric;
  41. ALTER TABLE exchangerate ALTER COLUMN buy TYPE numeric;
  42. ALTER TABLE exchangerate ALTER COLUMN sell TYPE numeric;
  43. ALTER TABLE vendor ALTER COLUMN discount TYPE numeric;
  44. ALTER TABLE vendor ALTER COLUMN creditlimit TYPE numeric;
  45. ALTER TABLE project ALTER COLUMN production TYPE numeric;
  46. ALTER TABLE project ALTER COLUMN completed TYPE numeric;
  47. ALTER TABLE business ALTER COLUMN discount TYPE numeric;
  48. ALTER TABLE inventory ALTER COLUMN qty TYPE numeric;
  49. ALTER TABLE partsvendor ALTER COLUMN lastcost TYPE numeric(10,2);
  50. ALTER TABLE partscustomer ALTER COLUMN pricebreak TYPE numeric;
  51. ALTER TABLE partscustomer ALTER COLUMN sellprice TYPE numeric(10,2);
  52. ALTER TABLE jcitems ALTER COLUMN qty TYPE numeric;
  53. ALTER TABLE jcitems ALTER COLUMN allocated TYPE numeric;
  54. ALTER TABLE jcitems ALTER COLUMN sellprice TYPE numeric(10,2);
  55. ALTER TABLE jcitems ALTER COLUMN fxsellprice TYPE numeric(10,2);
  56. -- The query rewrite rule necessary to notify the email app that a new report
  57. -- needs to be sent to the designated administrator.
  58. -- By Chris Travers
  59. -- chris@metatrontech.com
  60. -- Licensed under the GNU GPL 2.0 or later at your option. See accompanying
  61. -- GPL.txt
  62. CREATE OR REPLACE FUNCTION trigger_parts_short() RETURNS TRIGGER
  63. AS
  64. '
  65. BEGIN
  66. IF NEW.onhand >= NEW.rop THEN
  67. NOTIFY parts_short;
  68. END IF;
  69. RETURN NEW;
  70. END;
  71. ' LANGUAGE PLPGSQL;
  72. CREATE TRIGGER parts_short AFTER UPDATE ON parts
  73. FOR EACH ROW EXECUTE PROCEDURE trigger_parts_short();
  74. COMMIT;