Skip to content

Commit 44cf63c

Browse files
committed
[3.4 Upgrade Script] Writing migrations for v3.4
Developers should be able to use migrations to move their bcms 3.3/earlier sites to v3.4. Add migrations for v3.4. * Correct database to add namespacing to models/types that have class names in the database. * Fixed issue where projects with no cms table namespacing couldn't create portlets. * Define migration for upgrading to v3.4.0 * Changed naming convention of migration upgrades since Rails 3.1.x automatically compresses files names like browsercms_3_4_0 into browsercms340 (uses camelize) when it copies. * Use cms:install:migrations instead of copying using a generator * Update tests for generators
1 parent 20c19cb commit 44cf63c

File tree

21 files changed

+174
-96
lines changed

21 files changed

+174
-96
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ doc/api
2121
.yardoc/*
2222
.rvmrc
2323
.bundle/*
24+
test/dummy/db/backups/*

Gemfile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ source 'http://rubygems.org'
44
gemspec
55

66
gem 'jquery-rails'
7-
gem 'rack', '1.3.3' # At least until 1.3.5 is out. Avoids warnings about already defined constants.
87
gem "mysql2"
9-
10-
11-
128
gem 'yard', :groups=>[:development, :test]
139
gem 'bluecloth', :groups=>[:development, :test] # For YARD
1410

Gemfile.lock

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,36 @@ PATH
99
GEM
1010
remote: http://rubygems.org/
1111
specs:
12-
actionmailer (3.1.0)
13-
actionpack (= 3.1.0)
12+
actionmailer (3.1.3)
13+
actionpack (= 3.1.3)
1414
mail (~> 2.3.0)
15-
actionpack (3.1.0)
16-
activemodel (= 3.1.0)
17-
activesupport (= 3.1.0)
15+
actionpack (3.1.3)
16+
activemodel (= 3.1.3)
17+
activesupport (= 3.1.3)
1818
builder (~> 3.0.0)
1919
erubis (~> 2.7.0)
2020
i18n (~> 0.6)
21-
rack (~> 1.3.2)
22-
rack-cache (~> 1.0.3)
21+
rack (~> 1.3.5)
22+
rack-cache (~> 1.1)
2323
rack-mount (~> 0.8.2)
2424
rack-test (~> 0.6.1)
25-
sprockets (~> 2.0.0)
26-
activemodel (3.1.0)
27-
activesupport (= 3.1.0)
28-
bcrypt-ruby (~> 3.0.0)
25+
sprockets (~> 2.0.3)
26+
activemodel (3.1.3)
27+
activesupport (= 3.1.3)
2928
builder (~> 3.0.0)
3029
i18n (~> 0.6)
31-
activerecord (3.1.0)
32-
activemodel (= 3.1.0)
33-
activesupport (= 3.1.0)
30+
activerecord (3.1.3)
31+
activemodel (= 3.1.3)
32+
activesupport (= 3.1.3)
3433
arel (~> 2.2.1)
3534
tzinfo (~> 0.3.29)
36-
activeresource (3.1.0)
37-
activemodel (= 3.1.0)
38-
activesupport (= 3.1.0)
39-
activesupport (3.1.0)
35+
activeresource (3.1.3)
36+
activemodel (= 3.1.3)
37+
activesupport (= 3.1.3)
38+
activesupport (3.1.3)
4039
multi_json (~> 1.0)
4140
addressable (2.2.6)
4241
arel (2.2.1)
43-
bcrypt-ruby (3.0.1)
4442
bluecloth (2.1.0)
4543
builder (3.0.0)
4644
capybara (1.1.1)
@@ -77,55 +75,56 @@ GEM
7775
jquery-rails (1.0.14)
7876
railties (~> 3.0)
7977
thor (~> 0.14)
80-
json (1.6.1)
78+
json (1.6.3)
8179
json_pure (1.6.1)
8280
launchy (2.0.5)
8381
addressable (~> 2.2.6)
8482
mail (2.3.0)
8583
i18n (>= 0.4.0)
8684
mime-types (~> 1.16)
8785
treetop (~> 1.4.8)
88-
mime-types (1.16)
86+
mime-types (1.17.2)
8987
mocha (0.9.8)
9088
rake
91-
multi_json (1.0.3)
89+
multi_json (1.0.4)
9290
mysql2 (0.3.10)
9391
nokogiri (1.5.0)
94-
polyglot (0.3.2)
95-
rack (1.3.3)
96-
rack-cache (1.0.3)
92+
polyglot (0.3.3)
93+
rack (1.3.5)
94+
rack-cache (1.1)
9795
rack (>= 0.4)
9896
rack-mount (0.8.3)
9997
rack (>= 1.0.0)
10098
rack-ssl (1.3.2)
10199
rack
102100
rack-test (0.6.1)
103101
rack (>= 1.0)
104-
rails (3.1.0)
105-
actionmailer (= 3.1.0)
106-
actionpack (= 3.1.0)
107-
activerecord (= 3.1.0)
108-
activeresource (= 3.1.0)
109-
activesupport (= 3.1.0)
102+
rails (3.1.3)
103+
actionmailer (= 3.1.3)
104+
actionpack (= 3.1.3)
105+
activerecord (= 3.1.3)
106+
activeresource (= 3.1.3)
107+
activesupport (= 3.1.3)
110108
bundler (~> 1.0)
111-
railties (= 3.1.0)
112-
railties (3.1.0)
113-
actionpack (= 3.1.0)
114-
activesupport (= 3.1.0)
109+
railties (= 3.1.3)
110+
railties (3.1.3)
111+
actionpack (= 3.1.3)
112+
activesupport (= 3.1.3)
115113
rack-ssl (~> 1.3.2)
116114
rake (>= 0.8.7)
117115
rdoc (~> 3.4)
118116
thor (~> 0.14.6)
119-
rake (0.9.2)
120-
rdoc (3.9.4)
117+
rake (0.9.2.2)
118+
rdoc (3.11)
119+
json (~> 1.4)
121120
ruby-prof (0.10.8)
122121
rubyzip (0.9.4)
123122
selenium-webdriver (2.8.0)
124123
childprocess (>= 0.2.1)
125124
ffi (>= 1.0.7)
126125
json_pure
127126
rubyzip
128-
sprockets (2.0.0)
127+
sprockets (2.0.3)
129128
hike (~> 1.2)
130129
rack (~> 1.0)
131130
tilt (~> 1.1, != 1.3.0)
@@ -139,7 +138,7 @@ GEM
139138
treetop (1.4.10)
140139
polyglot
141140
polyglot (>= 0.3.1)
142-
tzinfo (0.3.29)
141+
tzinfo (0.3.31)
143142
xpath (0.1.4)
144143
nokogiri (~> 1.3)
145144
yard (0.7.2)
@@ -159,7 +158,6 @@ DEPENDENCIES
159158
launchy
160159
mocha (= 0.9.8)
161160
mysql2
162-
rack (= 1.3.3)
163161
ruby-prof
164162
sqlite3-ruby
165163
test-unit (= 2.1.1)

Rakefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ task :test => 'app:test:prepare' do
6767
end
6868
end
6969

70-
#task :test => ['test:units', 'test:functionals', 'test:integration', 'features']
71-
7270
task :default => :test
71+
72+
# Sample tasks to load sample data. This is unworking pseudocode at the moment.
73+
#task 'db:load' do
74+
# `mysql --user=root --password name_of_database < test/dummy/db/backups/name_of_file.sql`
75+
#end
76+
77+
#task 'db:dump' do
78+
# `mysqldump --user=name_of_user --password --database name_of_database > name_of_file.sql`
79+
#end

app/models/cms/portlet.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ def self.inherited(subclass)
1818
ensure
1919
subclass.class_eval do
2020

21+
# Using the table prefix here is NOT tested, since unloading classes is hard during tests.
2122
has_dynamic_attributes :class_name => "CmsPortletAttribute",
2223
:foreign_key => "portlet_id",
23-
:table_name => Cms::Portlet.table_name,
24+
:table_name => Namespacing.prefix("portlet_attributes"),
2425
:relationship_name => :portlet_attributes
2526

2627
acts_as_content_block(

bin/bcms

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ SITE_DOMAIN="localhost:3000"
166166
run_bundle_install(name)
167167
generate :jdbc if defined?(JRUBY_VERSION)
168168
route "mount_browsercms"
169+
rake 'cms:install:migrations'
169170
generate "browser_cms:cms"
170171
add_sitedomain_constant_to_environment_files
171172
configure_default_cache_directory
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Upgrade to Browsercms v3.4.0
2+
class Browsercms340 < ActiveRecord::Migration
3+
4+
def change
5+
# Prefix the correct namespace where class_names are not prefixed
6+
%w[HtmlBlock Category CategoryType Portlet FileBlock ImageBlock Tag].each do |content_type|
7+
update_content_types(content_type)
8+
update_connectors_table(content_type)
9+
end
10+
11+
update_sitemap
12+
update_files
13+
14+
end
15+
16+
17+
private
18+
19+
def prefix(name)
20+
"Cms::#{name}"
21+
end
22+
23+
def update_files
24+
%w[FileBlock ImageBlock].each do |content_type|
25+
Cms::AbstractFileBlock.update_all("type = '#{prefix(content_type)}'", "type = '#{content_type}'")
26+
end
27+
end
28+
29+
def update_sitemap
30+
%w[Section Page Link Attachment].each do |addressable|
31+
Cms::SectionNode.where(:node_type=>addressable).each do |node|
32+
node.node_type = prefix(addressable)
33+
node.save!
34+
end
35+
end
36+
end
37+
38+
def update_content_types(name)
39+
found = Cms::ContentType.named(name).first
40+
if found
41+
found.name = prefix(name)
42+
found.save!
43+
end
44+
end
45+
46+
def update_connectors_table(name)
47+
Cms::Connector.where(:connectable_type => name).each do |connector|
48+
connector.connectable_type = prefix(name)
49+
connector.save!
50+
end
51+
end
52+
end

doc/upgrading_notes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Upgrading to bcms 3.4
2+
3+
* Ensure there is no table prefix set (i.e. tables will in versions prior to 3.4 were not prefixed with cms_
4+
15
New Project using 3.3
26
===============
37
gem install browsercms

lib/cms/behaviors/dynamic_attributes.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def has_dynamic_attributes(options={})
127127
@has_dynamic_attributes = true
128128
include InstanceMethods
129129

130-
# Provide default options
130+
# Provide default options
131131
options[:class_name] ||= self.model_name + 'Attribute'
132132
options[:table_name] ||= options[:class_name].tableize
133133
options[:relationship_name] ||= options[:class_name].tableize.to_sym
@@ -150,6 +150,7 @@ def has_dynamic_attributes(options={})
150150
rescue
151151
Object.const_set(options[:class_name],
152152
Class.new(ActiveRecord::Base)).class_eval do
153+
set_table_name options[:table_name]
153154
def self.reloadable? #:nodoc:
154155
false
155156
end
@@ -171,7 +172,6 @@ def self.reloadable? #:nodoc:
171172
class_eval do
172173
has_many options[:relationship_name],
173174
:class_name => options[:class_name],
174-
:table_name => options[:table_name],
175175
:foreign_key => options[:foreign_key],
176176
:dependent => :destroy
177177

@@ -180,9 +180,8 @@ def self.reloadable? #:nodoc:
180180

181181
# Carry out delayed actions before save
182182
after_validation :save_modified_dynamic_attributes
183-
# after_validation_on_update :save_modified_dynamic_attributes
184183

185-
# Make attributes seem real
184+
# Make attributes seem real
186185
alias_method :method_missing_without_dynamic_attributes, :method_missing
187186
alias_method :method_missing, :method_missing_with_dynamic_attributes
188187

lib/generators/browser_cms/cms/cms_generator.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ module Generators
55
# For creating a new BrowserCMS project (Used in conjunction with the blank, demo and module templates.
66
class CmsGenerator < Base
77

8-
def copy_migrations_and_custom_js_files
8+
def copy_seed_files
99

1010
files_to_copy = [
11-
# Migrations/seed data
12-
'db/migrate/20080815014337_browsercms_3_0_0.rb',
13-
'db/migrate/20091109175123_browsercms_3_0_5.rb',
14-
'db/migrate/20100705083859_browsercms_3_3_0.rb',
15-
'db/browsercms.seeds.rb'
11+
'db/browsercms.seeds.rb'
1612
]
1713

1814
files_to_copy.each do |file|

0 commit comments

Comments
 (0)