summaryrefslogtreecommitdiff
path: root/sql/upgrade/1.2-1.3.sql
blob: 0db60863cb89c51d93d2efcbbbe0c6b8fe0c6bba (plain)
  1. BEGIN;
  2. ALTER TABLE employee RENAME TO employees;
  3. CREATE TABLE locations (
  4. id SERIAL PRIMARY KEY,
  5. companyname text,
  6. address1 text,
  7. address2 text,
  8. city text,
  9. state text,
  10. country text,
  11. zipcode text
  12. );
  13. CREATE SEQUENCE employees_id_seq;
  14. SELECT setval('employees_id_seq', (select max(id) + 1 FROM employees));
  15. ALTER TABLE employees ADD COLUMN locations_id integer;
  16. ALTER TABLE employees ADD FOREIGN KEY (locations_id) REFERENCES locations(id);
  17. ALTER TABLE employees ALTER COLUMN id DROP DEFAULT;
  18. ALTER TABLE employees ALTER COLUMN id SET DEFAULT nextval('employees_id_seq');
  19. DROP RULE employee_id_track_i ON employees; -- no longer needed
  20. COMMIT;