summaryrefslogtreecommitdiff
path: root/sql/Pg-upgrade-2.6.18-2.6.19.sql
blob: 924bd0ba4e20e93ed73ee3d4887e299d8ffa31c3 (plain)
  1. ALTER TABLE ap ADD PRIMARY KEY (id);
  2. ALTER TABLE ar ADD PRIMARY KEY (id);
  3. ALTER TABLE assembly ADD PRIMARY KEY (id, parts_id);
  4. ALTER TABLE business ADD PRIMARY KEY (id);
  5. ALTER TABLE customer ADD PRIMARY KEY (id);
  6. ALTER TABLE customertax ADD PRIMARY KEY (customer_id, chart_id);
  7. ALTER TABLE defaults ADD PRIMARY KEY (version);
  8. ALTER TABLE department ADD PRIMARY KEY (id);
  9. ALTER TABLE dpt_trans ADD PRIMARY KEY (trans_id);
  10. ALTER TABLE employee ADD PRIMARY KEY (id);
  11. ALTER TABLE exchangerate ADD PRIMARY KEY (curr, transdate);
  12. ALTER TABLE gifi ADD PRIMARY KEY (accno);
  13. ALTER TABLE gl ADD PRIMARY KEY (id);
  14. ALTER TABLE invoice ADD PRIMARY KEY (id);
  15. ALTER TABLE jcitems ADD PRIMARY KEY (id);
  16. ALTER TABLE language ADD PRIMARY KEY (code);
  17. ALTER TABLE makemodel ADD PRIMARY KEY (parts_id);
  18. ALTER TABLE oe ADD PRIMARY KEY (id);
  19. ALTER TABLE orderitems ADD PRIMARY KEY (id);
  20. ALTER TABLE parts ADD PRIMARY KEY (id);
  21. ALTER TABLE partsgroup ADD PRIMARY KEY (id);
  22. ALTER TABLE partstax ADD PRIMARY KEY (parts_id, chart_id);
  23. ALTER TABLE pricegroup ADD PRIMARY KEY (id);
  24. ALTER TABLE project ADD PRIMARY KEY (id);
  25. ALTER TABLE recurringemail ADD PRIMARY KEY (id);
  26. ALTER TABLE recurring ADD PRIMARY KEY (id);
  27. ALTER TABLE recurringprint ADD PRIMARY KEY (id);
  28. ALTER TABLE sic ADD PRIMARY KEY (code);
  29. ALTER TABLE status ADD PRIMARY KEY (trans_id);
  30. ALTER TABLE tax ADD PRIMARY KEY (chart_id);
  31. ALTER TABLE tax ADD FOREIGN KEY (chart_id) REFERENCES chart (id);
  32. ALTER TABLE translation ADD PRIMARY KEY (trans_id, language_code);
  33. ALTER TABLE vendor ADD PRIMARY KEY (id);
  34. ALTER TABLE vendortax ADD PRIMARY KEY (vendor_id, chart_id);
  35. ALTER TABLE warehouse ADD PRIMARY KEY (id);
  36. ALTER TABLE yearend ADD PRIMARY KEY (trans_id);
  37. LOCK inventory in EXCLUSIVE mode;
  38. ALTER TABLE inventory ADD COLUMN entry_id bigint;
  39. CREATE SEQUENCE inventory_entry_id_seq;
  40. ALTER TABLE inventory ALTER COLUMN entry_id
  41. SET DEFAULT nextval('inventory_entry_id_seq');
  42. UPDATE inventory SET entry_id = nextval('inventory_entry_id_seq');
  43. ALTER TABLE inventory ADD PRIMARY key (entry_id);
  44. LOCK partscustomer IN EXCLUSIVE MODE;
  45. ALTER TABLE partscustomer ADD COLUMN entry_id int;
  46. CREATE SEQUENCE partscustomer_entry_id_seq;
  47. ALTER TABLE partscustomer ALTER COLUMN entry_id
  48. SET DEFAULT nextval('partscustomer_entry_id_seq');
  49. UPDATE partscustomer SET entry_id = nextval('partscustomer_entry_id_seq');
  50. ALTER TABLE partscustomer ADD PRIMARY KEY (entry_id);
  51. LOCK partsvendor IN EXCLUSIVE MODE;
  52. ALTER TABLE partsvendor ADD COLUMN entry_id int;
  53. CREATE SEQUENCE partsvendor_entry_id_seq;
  54. ALTER TABLE partsvendor ALTER COLUMN entry_id
  55. SET DEFAULT nextval('partsvendor_entry_id_seq');
  56. UPDATE partsvendor SET entry_id = nextval('partsvendor_entry_id_seq');
  57. ALTER TABLE partsvendor ADD PRIMARY KEY (entry_id);
  58. LOCK audittrail IN EXCLUSIVE MODE;
  59. ALTER TABLE audittrail ADD COLUMN entry_id int;
  60. CREATE SEQUENCE audittrail_entry_id_seq ;
  61. ALTER TABLE audittrail ALTER COLUMN entry_id
  62. SET DEFAULT nextval('audittrail_entry_id_seq');
  63. UPDATE audittrail SET entry_id = nextval('audittrail_entry_id_seq');
  64. ALTER TABLE audittrail ADD PRIMARY KEY (entry_id);
  65. LOCK shipto IN EXCLUSIVE MODE;
  66. ALTER TABLE shipto ADD COLUMN entry_id int;
  67. CREATE SEQUENCE shipto_entry_id_seq ;
  68. ALTER TABLE shipto ALTER COLUMN entry_id
  69. SET DEFAULT nextval('shipto_entry_id_seq');
  70. UPDATE shipto SET entry_id = nextval('shipto_entry_id_seq');
  71. ALTER TABLE shipto ADD PRIMARY KEY (entry_id);
  72. CREATE TABLE taxmodule (
  73. taxmodule_id serial PRIMARY KEY,
  74. taxmodulename text NOT NULL
  75. );
  76. INSERT INTO taxmodule (
  77. taxmodule_id, taxmodulename
  78. ) VALUES (
  79. 1, 'Simple'
  80. );
  81. LOCK tax IN EXCLUSIVE MODE;
  82. ALTER TABLE tax ADD COLUMN pass int DEFAULT 0;
  83. UPDATE tax SET pass = 0;
  84. ALTER TABLE tax ALTER COLUMN pass SET NOT NULL;
  85. ALTER TABLE tax ADD COLUMN taxmodule_id int REFERENCES taxmodule DEFAULT 1;
  86. UPDATE tax SET taxmodule_id = 1;
  87. ALTER TABLE tax ALTER COLUMN taxmodule_id SET NOT NULL;
  88. -- Fixed session table and add users table --
  89. BEGIN;
  90. LOCK session in EXCLUSIVE MODE;
  91. ALTER TABLE session ADD CONSTRAINT session_token_check check (length(token::text) = 32);
  92. ALTER TABLE session ADD column user_id integer not null references users(id);
  93. LOCK users in EXCLUSIVE MODE;
  94. CREATE TABLE users (id serial UNIQUE, username varchar(30) PRIMARY KEY);
  95. COMMENT ON TABLE users 'username is the primary key because we don't want duplicate users';
  96. LOCK users_conf in EXCLUSIVE MODE;
  97. CREATE TABLE users_conf(id integer primary key references users(id) deferrable initially deferred,
  98. acs text,
  99. address text,
  100. businessnumber text,
  101. company text,
  102. countrycode text,
  103. currency text,
  104. dateformat text,
  105. dbconnect text,
  106. dbdriver text default 'Pg',
  107. dbhost text default 'localhost',
  108. dbname text,
  109. dboptions text,
  110. dbpasswd text,
  111. dbport text,
  112. dbuser text,
  113. email text,
  114. fax text,
  115. menuwidth text,
  116. name text,
  117. numberformat text,
  118. password varchar(32) check(length(password) = 32),
  119. print text,
  120. printer text,
  121. role text,
  122. sid text,
  123. signature text,
  124. stylesheet text,
  125. tel text,
  126. templates text,
  127. timeout numeric,
  128. vclimit numeric);
  129. COMMENT ON TABLE users_conf IS 'This is a completely dumb table that is a place holder to get usersconf into the database. Next major release will have a much more sane implementation';
  130. COMMENT ON COLUMN users_conf.id IS 'Yes primary key with a FOREIGN KEY to users(id) is correct';
  131. COMMENT ON COLUMN users_conf.password IS 'This means we have to get rid of the current password stuff and move to presumably md5()';
  132. COMMIT;
  133. -- Admin user --
  134. BEGIN;
  135. INSERT INTO users(username) VALUES ('admin');
  136. INSERT INTO users_conf(id,password) VALUES (currval('users_id_seq'),NULL);
  137. COMMIT;
  138. -- Functions
  139. CREATE FUNCTION create_user(text) RETURNS int4 AS $$
  140. INSERT INTO users(username) VALUES ('$1');
  141. SELECT currval('user_id_seq');
  142. $$ LANGUAGE 'SQL';
  143. COMMENT ON FUNCTION create_user(text) IS $$ Function to create user Returns users.id if successful, else it is an error. $$;
  144. CREATE FUNCTION update_user(int4,text) RETURNS int4 AS $$
  145. UPDATE users SET username = '$2' WHERE id = $1;
  146. SELECT 1;
  147. $$ LANGUAGE 'SQL';
  148. COMMENT ON FUNCTION update_user(int4,text) IS $$ Takes int4 which is users.id and text which is username. Will update username based on id. Username is unique $$;