Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nbibler/1067482 to your computer and use it in GitHub Desktop.
Save nbibler/1067482 to your computer and use it in GitHub Desktop.
From 56145a7faf608ae8d91bba81024d8b32df31032b Mon Sep 17 00:00:00 2001
From: Nathaniel Bibler <nate@envylabs.com>
Date: Fri, 1 Jul 2011 01:23:19 -0400
Subject: [PATCH] Define custom big_primary_key column type for postgresql
---
config/initializers/postgresql.rb | 1 +
db/migrate/20110701044205_create_logins.rb | 5 +++--
db/schema.rb | 2 ++
3 files changed, 6 insertions(+), 2 deletions(-)
create mode 100644 config/initializers/postgresql.rb
diff --git a/config/initializers/postgresql.rb b/config/initializers/postgresql.rb
new file mode 100644
index 0000000..8408d15
--- /dev/null
+++ b/config/initializers/postgresql.rb
@@ -0,0 +1 @@
+ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:big_primary_key] = 'bigserial primary key'
diff --git a/db/migrate/20110701044205_create_logins.rb b/db/migrate/20110701044205_create_logins.rb
index 82f440b..5a95b4e 100644
--- a/db/migrate/20110701044205_create_logins.rb
+++ b/db/migrate/20110701044205_create_logins.rb
@@ -1,10 +1,11 @@
class CreateLogins < ActiveRecord::Migration
def change
- create_table :logins do |t|
+ create_table :logins, id: false, primary_key: 'id' do |t|
+ t.column :id, :big_primary_key
t.integer :user_id, null: false
t.string :ip_address
t.timestamp :created_at
end
- change_column :logins, :id, :integer, :limit => 8
+ add_index :logins, :user_id
end
end
diff --git a/db/schema.rb b/db/schema.rb
index 24f6f9b..227769d 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -18,6 +18,8 @@ ActiveRecord::Schema.define(:version => 20110701044205) do
t.datetime "created_at"
end
+ add_index "logins", ["user_id"], :name => "index_logins_on_user_id"
+
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
--
1.7.6+GitX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment