completed SMS gateway project
This commit is contained in:
24
db/migrate/20251019070342_create_gateways.rb
Normal file
24
db/migrate/20251019070342_create_gateways.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
class CreateGateways < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :gateways do |t|
|
||||
t.string :device_id, null: false
|
||||
t.string :name
|
||||
t.string :api_key_digest, null: false
|
||||
t.string :status, default: "offline"
|
||||
t.datetime :last_heartbeat_at
|
||||
t.integer :messages_sent_today, default: 0
|
||||
t.integer :messages_received_today, default: 0
|
||||
t.integer :total_messages_sent, default: 0
|
||||
t.integer :total_messages_received, default: 0
|
||||
t.boolean :active, default: true
|
||||
t.integer :priority, default: 1
|
||||
t.jsonb :metadata, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :gateways, :device_id, unique: true
|
||||
add_index :gateways, :status
|
||||
add_index :gateways, :active
|
||||
end
|
||||
end
|
||||
26
db/migrate/20251019070519_create_sms_messages.rb
Normal file
26
db/migrate/20251019070519_create_sms_messages.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
class CreateSmsMessages < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :sms_messages do |t|
|
||||
t.references :gateway, foreign_key: true
|
||||
t.string :message_id, null: false
|
||||
t.string :direction, null: false
|
||||
t.string :phone_number, null: false
|
||||
t.text :message_body, null: false
|
||||
t.string :status, default: "pending"
|
||||
t.text :error_message
|
||||
t.integer :retry_count, default: 0
|
||||
t.datetime :sent_at
|
||||
t.datetime :delivered_at
|
||||
t.datetime :failed_at
|
||||
t.jsonb :metadata, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :sms_messages, :message_id, unique: true
|
||||
add_index :sms_messages, :phone_number
|
||||
add_index :sms_messages, [:phone_number, :created_at]
|
||||
add_index :sms_messages, [:status, :created_at]
|
||||
add_index :sms_messages, :direction
|
||||
end
|
||||
end
|
||||
21
db/migrate/20251019070520_create_otp_codes.rb
Normal file
21
db/migrate/20251019070520_create_otp_codes.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class CreateOtpCodes < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :otp_codes do |t|
|
||||
t.string :phone_number, null: false
|
||||
t.string :code, null: false
|
||||
t.string :purpose, default: "authentication"
|
||||
t.datetime :expires_at, null: false
|
||||
t.boolean :verified, default: false
|
||||
t.datetime :verified_at
|
||||
t.integer :attempts, default: 0
|
||||
t.string :ip_address
|
||||
t.jsonb :metadata, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :otp_codes, :phone_number
|
||||
add_index :otp_codes, :expires_at
|
||||
add_index :otp_codes, [:phone_number, :verified, :expires_at]
|
||||
end
|
||||
end
|
||||
18
db/migrate/20251019070521_create_webhook_configs.rb
Normal file
18
db/migrate/20251019070521_create_webhook_configs.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class CreateWebhookConfigs < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :webhook_configs do |t|
|
||||
t.string :name, null: false
|
||||
t.string :url, null: false
|
||||
t.string :event_type, null: false
|
||||
t.string :secret_key
|
||||
t.boolean :active, default: true
|
||||
t.integer :timeout, default: 30
|
||||
t.integer :retry_count, default: 3
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :webhook_configs, :event_type
|
||||
add_index :webhook_configs, :active
|
||||
end
|
||||
end
|
||||
19
db/migrate/20251019070522_create_api_keys.rb
Normal file
19
db/migrate/20251019070522_create_api_keys.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class CreateApiKeys < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :api_keys do |t|
|
||||
t.string :name, null: false
|
||||
t.string :key_digest, null: false
|
||||
t.string :key_prefix, null: false
|
||||
t.boolean :active, default: true
|
||||
t.datetime :last_used_at
|
||||
t.datetime :expires_at
|
||||
t.jsonb :permissions, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :api_keys, :key_digest, unique: true
|
||||
add_index :api_keys, :key_prefix
|
||||
add_index :api_keys, :active
|
||||
end
|
||||
end
|
||||
14
db/migrate/20251020025135_create_admins.rb
Normal file
14
db/migrate/20251020025135_create_admins.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class CreateAdmins < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
create_table :admins do |t|
|
||||
t.string :email, null: false
|
||||
t.string :password_digest, null: false
|
||||
t.string :name, null: false
|
||||
t.datetime :last_login_at
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :admins, :email, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RenameAdminsToAdminUsers < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
rename_table :admins, :admin_users
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user