Class: CreateTodoroTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/todoro/templates/create_todoro_tasks.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/generators/todoro/templates/create_todoro_tasks.rb', line 2

def change
  create_table :todoro_tasks do |t|
    t.string :title
    t.text :description, null: false  # Description is required
    t.datetime :expiry_date
    t.string :status, null: false, default: "pending"  # Status is required
    t.references :task_list, null: false, foreign_key: { to_table: :todoro_task_lists }

    t.timestamps
  end

  # Enforce status constraint
  execute <<-SQL
    ALTER TABLE todoro_tasks
    ADD CONSTRAINT status_check
    CHECK (status IN ('pending', 'completed'));
  SQL
end