Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rails engine for migrations #60

Merged
merged 9 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,18 @@ Add *HasFriendship* to your Gemfile:
gem 'has_friendship'
```

After you install *HasFriendship*, you need to run the generator:

$ rails generate has_friendship

The generator will copy a migration that creates `friendships` table. Run the migration to finish the setup.
After you bundle *HasFriendship*, you need to copy migrations and migrate:

$ rails has_friendship:install:migrations
$ rake db:migrate

### Upgrading to 0.1.0

`0.1.0` adds a blocking feature for friendables. This requires an additional
column in the `friendships` table, and a migration should be run. You will need
to run the generator and run the new migration.
## Gem upgrades

### Upgrading to 1.x.x
After gem updates, it may be necessary to run subsequent migrations.

If upgrading from <= 0.1.3 to 1.x.x, please run the following generator:
$ rails has_friendship:install:migrations

$ rails generate has_friendship_update

Then, run the migration:

$ rake db:migrate
Will install _new_ migrations if they're necessary.

## Usage

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class CreateFriendships < ActiveRecord::Migration[4.2]
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
class CreateFriendships < ActiveRecord::Migration[4.2]; end
else
class CreateFriendships < ActiveRecord::Migration; end
end

CreateFriendships.class_eval do
def self.up
create_table :friendships do |t|
t.references :friendable, polymorphic: true
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/2_add_blocker_id_to_friendships.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
class AddBlockerIdToFriendships < ActiveRecord::Migration[4.2]; end
else
class AddBlockerIdToFriendships < ActiveRecord::Migration; end
end

AddBlockerIdToFriendships.class_eval do
def self.up
add_column :friendships, :blocker_id, :integer, default: nil
end

def self.down
remove_column :friendships, :blocker_id
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class UpdateFriendships < ActiveRecord::Migration[4.2]
if ActiveRecord.gem_version >= Gem::Version.new('5.0')
class UpdateFriendships < ActiveRecord::Migration[4.2]; end
else
class UpdateFriendships < ActiveRecord::Migration; end
end

UpdateFriendships.class_eval do
def self.up
add_column :friendships, :status_temp, :integer, index: true
HasFriendship::Friendship.where(status: 'pending').update_all(status_temp: 0)
Expand Down
26 changes: 0 additions & 26 deletions lib/generators/has_friendship/has_friendship_generator.rb

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 3 additions & 1 deletion lib/has_friendship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require 'active_support'
require 'active_record'
require 'rails/engine'
require 'has_friendship/engine'

module HasFriendship
extend ActiveSupport::Autoload
Expand All @@ -13,4 +15,4 @@ module HasFriendship

ActiveSupport.on_load(:active_record) do
extend HasFriendship::Friendable
end
end
5 changes: 5 additions & 0 deletions lib/has_friendship/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module HasFriendship
class Engine < ::Rails::Engine
# isolate_namespace HasFriendship
end
end
40 changes: 0 additions & 40 deletions spec/has_friendship/has_friendship_generator_spec.rb

This file was deleted.

38 changes: 0 additions & 38 deletions spec/has_friendship/has_friendship_generator_update_spec.rb

This file was deleted.