Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active Apr 10, 2022
Embed
What would you like to do?
-- 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