Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active April 10, 2022 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garystafford/04ed6f13c768b1301fcd2e0260a2b70a to your computer and use it in GitHub Desktop.
Save garystafford/04ed6f13c768b1301fcd2e0260a2b70a to your computer and use it in GitHub Desktop.
-- wrap in transaction
BEGIN;
-- optional, should be set to public by default
SET search_path TO public;
-- create new schemas
CREATE SCHEMA common;
CREATE SCHEMA customers;
CREATE SCHEMA films;
CREATE SCHEMA sales;
CREATE SCHEMA staff;
CREATE SCHEMA stores;
-- common
ALTER TABLE address SET SCHEMA common;
ALTER TABLE city SET SCHEMA common;
ALTER TABLE country SET SCHEMA common;
-- customers
ALTER TABLE customer SET SCHEMA customers;
-- films
ALTER TABLE actor SET SCHEMA films;
ALTER TABLE category SET SCHEMA films;
ALTER TABLE film SET SCHEMA films;
ALTER TABLE language SET SCHEMA films;
ALTER TABLE film_actor SET SCHEMA films;
ALTER TABLE film_category SET SCHEMA films;
-- sales
ALTER TABLE payment SET SCHEMA sales;
ALTER TABLE rental SET SCHEMA sales;
-- staff
ALTER TABLE staff SET SCHEMA staff;
-- stores
ALTER TABLE store SET SCHEMA stores;
ALTER TABLE inventory SET SCHEMA stores;
COMMIT;
-- confirm all tables are removed from public schema
\dt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment