Last active
August 29, 2015 14:16
-
-
Save warmwaffles/f3014f33205f37b3a77e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EnableUuidExtension < ActiveRecord::Migration | |
def up | |
execute %Q{CREATE EXTENSION "uuid-ossp"} | |
end | |
def down | |
execute %Q{DROP EXTENSION "uuid-ossp"} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateUpdateTrigger < ActiveRecord::Migration | |
def up | |
execute <<-SQL | |
CREATE FUNCTION update_modified_column() RETURNS trigger | |
LANGUAGE plpgsql | |
AS $$ | |
BEGIN | |
NEW.updated_at = now(); | |
RETURN NEW; | |
END; | |
$$; | |
SQL | |
end | |
def down | |
execute %Q{DROP FUNCTION update_modified_column} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CreateUsers < ActiveRecord::Migration | |
def up | |
execute <<-SQL | |
CREATE TABLE "users" ( | |
"id" UUID NOT NULL DEFAULT uuid_generate_v4(), | |
"email" CHARACTER VARYING DEFAULT ''::CHARACTER VARYING NOT NULL, | |
"encrypted_password" CHARACTER VARYING DEFAULT ''::CHARACTER VARYING NOT NULL, | |
"reset_password_token" CHARACTER VARYING, | |
"reset_password_sent_at" TIMESTAMP WITHOUT TIME ZONE, | |
"remember_created_at" TIMESTAMP WITHOUT TIME ZONE, | |
"sign_in_count" INTEGER DEFAULT 0 NOT NULL, | |
"current_sign_in_at" TIMESTAMP WITHOUT TIME ZONE, | |
"last_sign_in_at" TIMESTAMP WITHOUT TIME ZONE, | |
"current_sign_in_ip" INET, | |
"last_sign_in_ip" INET, | |
"confirmation_token" CHARACTER VARYING, | |
"confirmed_at" TIMESTAMP WITHOUT TIME ZONE, | |
"confirmation_sent_at" TIMESTAMP WITHOUT TIME ZONE, | |
"unconfirmed_email" CHARACTER VARYING, | |
"failed_attempts" INTEGER DEFAULT 0 NOT NULL, | |
"unlock_token" CHARACTER VARYING, | |
"locked_at" TIMESTAMP WITHOUT TIME ZONE, | |
"created_at" TIMESTAMP NOT NULL DEFAULT now(), | |
"updated_at" TIMESTAMP NOT NULL DEFAULT now(), | |
PRIMARY KEY ("id"), | |
UNIQUE("email"), | |
UNIQUE("confirmation_token"), | |
UNIQUE("unlock_token") | |
) | |
SQL | |
execute <<-SQL | |
CREATE TRIGGER "update_users_updated_at" | |
BEFORE UPDATE ON "users" | |
FOR EACH ROW | |
EXECUTE PROCEDURE update_modified_column() | |
SQL | |
end | |
def down | |
execute %Q{DROP TRIGGER "update_users_updated_at" ON "users"} | |
execute %Q{DROP TABLE "users"} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/active_record | |
ActiveRecord::Base.record_timestamps = false | |
ActiveRecord::Base.inheritance_column = :_type_disabled |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment