40
db/migrate/20201027135006_create_working_hours.rb
Normal file
40
db/migrate/20201027135006_create_working_hours.rb
Normal file
@@ -0,0 +1,40 @@
|
||||
class CreateWorkingHours < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :working_hours do |t|
|
||||
t.belongs_to :inbox
|
||||
t.belongs_to :account
|
||||
|
||||
t.integer :day_of_week, null: false
|
||||
t.boolean :closed_all_day, default: false
|
||||
t.integer :open_hour
|
||||
t.integer :open_minutes
|
||||
t.integer :close_hour
|
||||
t.integer :close_minutes
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_column :accounts, :timezone, :string, default: 'UTC'
|
||||
|
||||
change_table :inboxes, bulk: true do |t|
|
||||
t.boolean :working_hours_enabled, default: false
|
||||
t.string :out_of_office_message
|
||||
end
|
||||
|
||||
Inbox.where.not(id: WorkingHour.select(:inbox_id)).each do |inbox|
|
||||
create_working_hours_for_inbox(inbox)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_working_hours_for_inbox(inbox)
|
||||
inbox.working_hours.create!(day_of_week: 1, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
|
||||
inbox.working_hours.create!(day_of_week: 2, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
|
||||
inbox.working_hours.create!(day_of_week: 3, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
|
||||
inbox.working_hours.create!(day_of_week: 4, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
|
||||
inbox.working_hours.create!(day_of_week: 5, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
|
||||
inbox.working_hours.create!(day_of_week: 6, closed_all_day: true)
|
||||
inbox.working_hours.create!(day_of_week: 7, closed_all_day: true)
|
||||
end
|
||||
end
|
||||
20
db/schema.rb
20
db/schema.rb
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_10_19_173944) do
|
||||
ActiveRecord::Schema.define(version: 2020_10_27_135006) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
@@ -49,6 +49,7 @@ ActiveRecord::Schema.define(version: 2020_10_19_173944) do
|
||||
t.string "support_email", limit: 100
|
||||
t.integer "settings_flags", default: 0, null: false
|
||||
t.integer "feature_flags", default: 0, null: false
|
||||
t.string "timezone", default: "UTC"
|
||||
end
|
||||
|
||||
create_table "action_mailbox_inbound_emails", force: :cascade do |t|
|
||||
@@ -280,6 +281,8 @@ ActiveRecord::Schema.define(version: 2020_10_19_173944) do
|
||||
t.boolean "greeting_enabled", default: false
|
||||
t.string "greeting_message"
|
||||
t.string "email_address"
|
||||
t.boolean "working_hours_enabled", default: false
|
||||
t.string "out_of_office_message"
|
||||
t.index ["account_id"], name: "index_inboxes_on_account_id"
|
||||
end
|
||||
|
||||
@@ -513,6 +516,21 @@ ActiveRecord::Schema.define(version: 2020_10_19_173944) do
|
||||
t.index ["account_id", "url"], name: "index_webhooks_on_account_id_and_url", unique: true
|
||||
end
|
||||
|
||||
create_table "working_hours", force: :cascade do |t|
|
||||
t.bigint "inbox_id"
|
||||
t.bigint "account_id"
|
||||
t.integer "day_of_week", null: false
|
||||
t.boolean "closed_all_day", default: false
|
||||
t.integer "open_hour"
|
||||
t.integer "open_minutes"
|
||||
t.integer "close_hour"
|
||||
t.integer "close_minutes"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["account_id"], name: "index_working_hours_on_account_id"
|
||||
t.index ["inbox_id"], name: "index_working_hours_on_inbox_id"
|
||||
end
|
||||
|
||||
add_foreign_key "account_users", "accounts"
|
||||
add_foreign_key "account_users", "users"
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
|
||||
Reference in New Issue
Block a user