diff options
author | Scott Barron <scott@elitists.net> | 2005-09-25 10:52:16 +0000 |
---|---|---|
committer | Scott Barron <scott@elitists.net> | 2005-09-25 10:52:16 +0000 |
commit | e7059fd28191a77d53e66389f8df5b22036699e8 (patch) | |
tree | 315e40546582e31fa195b87a0ce1304542644e01 /activerecord/lib/active_record | |
parent | fa7d4a691ff4fb245c1fd0c62a11f908d5a1bcd9 (diff) | |
download | rails-e7059fd28191a77d53e66389f8df5b22036699e8.tar.gz rails-e7059fd28191a77d53e66389f8df5b22036699e8.tar.bz2 rails-e7059fd28191a77d53e66389f8df5b22036699e8.zip |
Fix migrations with PG 7.x.
Closes #1850
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2332 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 74b4440329..0fe2517657 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -159,6 +159,19 @@ module ActiveRecord alias_method :delete, :update + def add_column(table_name, column_name, type, options = {}) + native_type = native_database_types[type] + sql_commands = ["ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type, options[:limit])}"] + if options[:default] + sql_commands << "ALTER TABLE #{table_name} ALTER #{column_name} SET DEFAULT '#{options[:default]}'" + end + if options[:null] == false + sql_commands << "ALTER TABLE #{table_name} ALTER #{column_name} SET NOT NULL" + end + sql_commands.each { |cmd| execute(cmd) } + end + + def begin_db_transaction() execute "BEGIN" end def commit_db_transaction() execute "COMMIT" end def rollback_db_transaction() execute "ROLLBACK" end |