From 77e4f226560ffce9a331687a422543bba789d8f9 Mon Sep 17 00:00:00 2001 From: Praveen Devarao Date: Thu, 29 Jul 2010 16:49:13 +0530 Subject: [PATCH] Added method SchemaStatements::unique_constraint to provide flexibility to handle database specifics for unique constraints. Also modified method SessionStore#create_table! to retrieve column types through adapters and remove hard coding of the datatypes and made use of unique_constraint method to handle unique constraint --- .../abstract/schema_statements.rb | 7 +++++++ activerecord/lib/active_record/session_store.rb | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index ffc3847..6884d77 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -495,6 +495,13 @@ module ActiveRecord end end + # Some databases like DB2 require that not null be specified explcitly, when UNIQUE, + # as Unique columns dont allow null values. + # Respective adapter can override to handle specifics in case other than default. + def unique_constraint(options = nil) + " UNIQUE " + end + def add_column_options!(sql, options) #:nodoc: sql << " DEFAULT #{quote(options[:default], options[:column])}" if options_include_default?(options) # must explicitly check for :null to allow change_column to work on migrations diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb index 766e63e..acb379e 100644 --- a/activerecord/lib/active_record/session_store.rb +++ b/activerecord/lib/active_record/session_store.rb @@ -66,8 +66,8 @@ module ActiveRecord connection.execute <<-end_sql CREATE TABLE #{table_name} ( id #{connection.type_to_sql(:primary_key)}, - #{connection.quote_column_name(session_id_column)} VARCHAR(255) UNIQUE, - #{connection.quote_column_name(data_column_name)} TEXT + #{connection.quote_column_name(session_id_column)} #{connection.type_to_sql(:string,255)} #{connection.unique_constraint}, + #{connection.quote_column_name(data_column_name)} #{connection.type_to_sql(:text)} ) end_sql end -- 1.6.0