From 1de273c96ee642388b350d8612a7e4593453c061 Mon Sep 17 00:00:00 2001 From: lrbalt Date: Tue, 4 Mar 2008 20:06:51 +0000 Subject: [PATCH] this patch includes a fix to the sqlite adapter to support changing NOT NULL constraints on existing sqlite databases. This fix is part of rails 2.0, but not part of rails 1.2.6 which is baseline for tracks 1.5. Also this patch includes a migration to remove the NOT NULL constaint from the position field of contexts and projects. Should solve #640 git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@722 a4c988fc-2ded-0310-b66e-134b36920a42 --- ..._contexts_remove_not_null_from_position.rb | 22 +++++++++++++++++++ .../connection_adapters/sqlite_adapter.rb | 1 + 2 files changed, 23 insertions(+) create mode 100644 tracks/db/migrate/038_projects_contexts_remove_not_null_from_position.rb diff --git a/tracks/db/migrate/038_projects_contexts_remove_not_null_from_position.rb b/tracks/db/migrate/038_projects_contexts_remove_not_null_from_position.rb new file mode 100644 index 00000000..fe9e198f --- /dev/null +++ b/tracks/db/migrate/038_projects_contexts_remove_not_null_from_position.rb @@ -0,0 +1,22 @@ +class ProjectsContextsRemoveNotNullFromPosition < ActiveRecord::Migration + def self.up + change_column :projects, :position, :string, :null => true + change_column :contexts, :position, :string, :null => true + end + + def self.down + @projects = Project.find(:all) + @projects.each do |project| + project.position = 0 if !project.position? + project.save + end + change_column :projects, :position, :string, :null => false + + @contexts = Context.find(:all) + @contexts.each do |context| + context.position = 0 if !context.position? + context.save + end + change_column :contexts, :position, :string, :null => false + end +end diff --git a/tracks/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/tracks/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 0a9c57e1..fbfd79f3 100644 --- a/tracks/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/tracks/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -259,6 +259,7 @@ module ActiveRecord self.type = type self.limit = options[:limit] if options.include?(:limit) self.default = options[:default] if include_default + self.null = options[:null] if options.include?(:null) end end end