diff --git a/Gemfile b/Gemfile index 160b58f1d..b48d10426 100644 --- a/Gemfile +++ b/Gemfile @@ -7,4 +7,4 @@ workspace = ENV["WORKSPACE"] || "workspace" # $ cd [workspace] # $ git clone https://github.com/sethcall/pg_migrate_ruby -gem 'pg_migrate', '0.1.4' # :path=> '~/' + workspace + '/pg_migrate_ruby' +gem 'pg_migrate', '0.1.5' # :path=> '~/' + workspace + '/pg_migrate_ruby' diff --git a/Gemfile.lock b/Gemfile.lock index f6c8b3457..0383b3549 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,7 +5,7 @@ GEM logging (1.7.2) little-plugger (>= 1.1.3) pg (0.14.0) - pg_migrate (0.1.4) + pg_migrate (0.1.5) logging (= 1.7.2) pg (= 0.14.0) thor (= 0.15.4) @@ -15,4 +15,4 @@ PLATFORMS ruby DEPENDENCIES - pg_migrate (= 0.1.4) + pg_migrate (= 0.1.5) diff --git a/README.md b/README.md index b9c149952..283a56f25 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Then, to cause a migration, do something like: bundle install # migrate the database (assumes you've created the 'jam' database already). -bundle exec jam_db --connopts="dbname:jam host:localhost user:postgres password:postgres" --verbose +bundle exec jam_db up --connopts="dbname:jam host:localhost user:postgres password:postgres" --verbose # you can see if it worked by typing: diff --git a/up/sessions.sql b/up/sessions.sql index 4fc0132d6..294725195 100644 --- a/up/sessions.sql +++ b/up/sessions.sql @@ -34,4 +34,30 @@ CREATE TABLE jam_session_members ( ALTER TABLE jam_session_members ADD CONSTRAINT user_jam_session_uniqkey UNIQUE (user_id, jam_session_id); +-- create a utility method to truncate all tables + +CREATE OR REPLACE FUNCTION truncate_tables() RETURNS void AS $$ +DECLARE + statements CURSOR FOR + SELECT tablename FROM pg_tables + WHERE schemaname = 'public'; +BEGIN + FOR stmt IN statements LOOP + EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;'; + END LOOP; +END; +$$ LANGUAGE plpgsql; + +-- create a utility that bootstraps a user +CREATE OR REPLACE FUNCTION bootstrap_users() RETURNS void AS $$ +DECLARE + +BEGIN + -- non guid used for test user. test user won't be in actual database, but '1' is much easier to script that 242423-42-4-24234 + -- password is jam123 + INSERT INTO users (id, name, email, remember_token, password_digest) VALUES ('1', 'test', 'test@jamkazam.com', 'NQubl-z16Em94tnSdofObw', '$2a$10$QyaNTLVX5DAaJ.JL21kDWeUQqdh3Qh7JQbdRgE82x1Cib7HWNcHXC'); +END; +$$ LANGUAGE plpgsql; + +select bootstrap_users();