aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-04 18:51:02 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-04 18:51:02 +0000
commit4160b518a82bcaa84e0e3125b4947b2dc3837fa3 (patch)
treedef4e797e1834c65864498509ea98edd7dad7745 /activerecord/lib/active_record/connection_adapters
parent452442dde8e8ea5949c387ea5c78387bff330f2a (diff)
downloadrails-4160b518a82bcaa84e0e3125b4947b2dc3837fa3.tar.gz
rails-4160b518a82bcaa84e0e3125b4947b2dc3837fa3.tar.bz2
rails-4160b518a82bcaa84e0e3125b4947b2dc3837fa3.zip
Added new Migrations framework for describing schema transformations in a way that can be easily applied across multiple databases #1604 [Tobias Luetke]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1672 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/abstract_adapter.rb19
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/mysql_adapter.rb5
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb21
3 files changed, 40 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 1137ea1011..1b5c8184ae 100755
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -357,9 +357,10 @@ module ActiveRecord
sql << " OFFSET #{options[:offset]}" if options.has_key?(:offset) and !options[:offset].nil?
end
+
def initialize_schema_information
begin
- execute "CREATE TABLE schema_info (version #{native_database_types[:integer][:name]}(#{native_database_types[:integer][:limit]}))"
+ execute "CREATE TABLE schema_info (version #{type_to_sql(:integer)})"
insert "INSERT INTO schema_info (version) VALUES(0)"
rescue ActiveRecord::StatementInvalid
# Schema has been intialized
@@ -378,8 +379,7 @@ module ActiveRecord
def add_column(table_name, column_name, type, options = {})
native_type = native_database_types[type]
- add_column_sql = "ALTER TABLE #{table_name} ADD #{column_name} #{native_type[:name]}"
- add_column_sql << "(#{options[:limit] || native_type[:limit]})" if options[:limit] || native_type[:limit]
+ add_column_sql = "ALTER TABLE #{table_name} ADD #{column_name} #{type_to_sql(type)}"
add_column_sql << " DEFAULT '#{options[:default]}'" if options[:default]
execute(add_column_sql)
end
@@ -387,9 +387,20 @@ module ActiveRecord
def remove_column(table_name, column_name)
execute "ALTER TABLE #{table_name} DROP #{column_name}"
end
+
+ def supports_migrations?
+ false
+ end
protected
+ def type_to_sql(type)
+ native = native_database_types[type]
+ column_type_sql = native[:name]
+ column_type_sql << "(#{native[:limit]})" if native[:limit]
+ column_type_sql
+ end
+
def log(sql, name)
begin
if block_given?
@@ -439,7 +450,7 @@ module ActiveRecord
"%s %s" % [message, dump]
end
end
- end
+ end
class TableDefinition
attr_accessor :columns
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index ad0e490194..ec0558a4d5 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -63,6 +63,10 @@ module ActiveRecord
"Lost connection to MySQL server during query",
"MySQL server has gone away"
]
+
+ def supports_migrations?
+ true
+ end
def native_database_types
{
@@ -89,7 +93,6 @@ module ActiveRecord
'MySQL'
end
-
def select_all(sql, name = nil)
select(sql, name)
end
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 66cbe3a58b..3d6550ea9a 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -60,6 +60,27 @@ module ActiveRecord
# * <tt>:encoding</tt> -- An optional client encoding that is using in a SET client_encoding TO <encoding> call on connection.
# * <tt>:min_messages</tt> -- An optional client min messages that is using in a SET client_min_messages TO <min_messages> call on connection.
class PostgreSQLAdapter < AbstractAdapter
+
+ def native_database_types
+ {
+ :primary_key => "serial primary key",
+ :string => { :name => "character varying", :limit => 255 },
+ :text => { :name => "text" },
+ :integer => { :name => "integer" },
+ :float => { :name => "float" },
+ :datetime => { :name => "timestamp" },
+ :timestamp => { :name => "timestamp" },
+ :time => { :name => "timestamp" },
+ :date => { :name => "date" },
+ :binary => { :name => "bytea" },
+ :boolean => { :name => "boolean"}
+ }
+ end
+
+ def supports_migrations?
+ true
+ end
+
def select_all(sql, name = nil)
select(sql, name)
end