Skip to content

Commit 15a11e0

Browse files
committed
Move to version v.1.3: Make migrations rails version compatible and ensure generator uses migration_template
1 parent adcc9f9 commit 15a11e0

12 files changed

+78
-7
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
todoro (0.1.2)
4+
todoro (0.1.3)
55
rails (~> 7.2.1)
66

77
GEM

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ $ gem install todoro
2828
Generate the required migrations
2929

3030
```ruby
31-
rails todoro:install:migrations
31+
rails generate todoro:install
3232
```
3333

3434
Include Taskable in the model(s) that can have tasks
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require "rails/generators"
2+
require "rails/generators/active_record"
3+
4+
module Todoro
5+
module Generators
6+
class InstallGenerator < Rails::Generators::Base
7+
include Rails::Generators::Migration
8+
source_root File.expand_path("templates", __dir__)
9+
10+
def create_migrations
11+
migration_template "create_todoro_task_lists.rb", "db/migrate/create_todoro_task_lists.rb"
12+
migration_template "create_todoro_tasks.rb", "db/migrate/create_todoro_tasks.rb"
13+
migration_template "create_todoro_reminders.rb", "db/migrate/create_todoro_reminders.rb"
14+
migration_template "add_indexes_to_todoro_tasks.rb", "db/migrate/add_indexes_to_todoro_tasks.rb"
15+
end
16+
17+
def self.next_migration_number(dirname)
18+
ActiveRecord::Generators::Base.next_migration_number(dirname)
19+
end
20+
end
21+
end
22+
end

db/migrate/20250215024110_add_indexes_to_todoro_tasks.rb renamed to lib/generators/todoro/templates/add_indexes_to_todoro_tasks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class AddIndexesToTodoroTasks < ActiveRecord::Migration[8.0]
1+
class AddIndexesToTodoroTasks < ActiveRecord::Migration[ActiveRecord::Migration.current_version]
22
def change
33
add_index :todoro_task_lists, [ :taskable_type, :taskable_id ]
44
add_index :todoro_tasks, :status

db/migrate/20250214104111_create_todoro_reminders.rb renamed to lib/generators/todoro/templates/create_todoro_reminders.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreateTodoroReminders < ActiveRecord::Migration[8.0]
1+
class CreateTodoroReminders < ActiveRecord::Migration[ActiveRecord::Migration.current_version]
22
def change
33
create_table :todoro_reminders do |t|
44
t.references :task, null: false, foreign_key: { to_table: :todoro_tasks }

db/migrate/20250214104107_create_todoro_task_lists.rb renamed to lib/generators/todoro/templates/create_todoro_task_lists.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreateTodoroTaskLists < ActiveRecord::Migration[8.0]
1+
class CreateTodoroTaskLists < ActiveRecord::Migration[ActiveRecord::Migration.current_version]
22
def change
33
create_table :todoro_task_lists do |t|
44
t.string :name, null: false

db/migrate/20250214104109_create_todoro_tasks.rb renamed to lib/generators/todoro/templates/create_todoro_tasks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreateTodoroTasks < ActiveRecord::Migration[8.0]
1+
class CreateTodoroTasks < ActiveRecord::Migration[ActiveRecord::Migration.current_version]
22
def change
33
create_table :todoro_tasks do |t|
44
t.string :title

lib/todoro/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Todoro
2-
VERSION = "0.1.2"
2+
VERSION = "0.1.3"
33
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class CreateTodoroTaskLists < ActiveRecord::Migration[ActiveRecord::Migration.current_version]
2+
def change
3+
create_table :todoro_task_lists do |t|
4+
t.string :name, null: false
5+
t.references :taskable, polymorphic: true, null: false
6+
7+
t.timestamps
8+
end
9+
end
10+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class CreateTodoroTasks < ActiveRecord::Migration[ActiveRecord::Migration.current_version]
2+
def change
3+
create_table :todoro_tasks do |t|
4+
t.string :title
5+
t.text :description, null: false # Description is required
6+
t.datetime :expiry_date
7+
t.string :status, null: false, default: "pending" # Status is required
8+
t.references :task_list, null: false, foreign_key: { to_table: :todoro_task_lists }
9+
10+
t.timestamps
11+
end
12+
13+
# Enforce status constraint
14+
execute <<-SQL
15+
ALTER TABLE todoro_tasks
16+
ADD CONSTRAINT status_check
17+
CHECK (status IN ('pending', 'completed'));
18+
SQL
19+
end
20+
end

0 commit comments

Comments
 (0)