Upgrade 3CX to v18 and get it hosted free!

Asterisk Realtime – Ruby on Rails Migrations and Models

Author image

Using Ruby on Rails Migrations the below will support any combination of database that ActiveRecord and Asterisk Realtime Architecture support, including of course MySQL and Postgres.

Ruby on Rails Models are then provided to be dropped into any Ruby on Rails application that requires the ability to configure Asterisk via the Asterisk Realtime Architecture.

Migrations (db/schema.rb)

 

ActiveRecord::Schema.define() do

  #Use the same table for IAX2 and SIP configuration
  create_table "devices", :force => true do |t|
    t.column :name,               :string, :limit => 80
    t.column :accountcode,        :string, :limit => 20
    t.column :amaflags,           :string, :limit => 13
    t.column :callgroup,          :string, :limit => 10
    t.column :callerid,           :string, :limit => 80
    t.column :canreinvite,        :string, :limit => 3, :default => 'yes'
    t.column :context,            :string, :limit => 80
    t.column :defaultip,          :string, :limit => 15
    t.column :dtmfmode,           :string, :limit => 7
    t.column :fromuser,           :string, :limit => 80
    t.column :fromdomain,         :string, :limit => 80
    t.column :fullcontact,        :string, :limit => 80
    t.column :host,               :string, :limit => 31, :default => 'dynamic'
    t.column :insecure,           :string, :limit => 4
    t.column :language,           :string, :limit => 2
    t.column :mailbox,            :string, :limit => 50
    t.column :md5secret,          :string, :limit => 80
    t.column :nat,                :string, :limit => 5, :default => 'no'
    t.column :deny,               :string, :limit => 95
    t.column :permit,             :string, :limit => 95
    t.column :mask,               :string, :limit => 95
    t.column :pickupgroup,        :string, :limit => 10
    t.column :port,               :string, :limit => 5, :default => ''
    t.column :qualify,            :string, :limit => 3
    t.column :restrictcid,        :string, :limit => 1
    t.column :rtptimeout,         :string, :limit => 3
    t.column :rtpholdtimeout,     :string, :limit => 3
    t.column :secret,             :string, :limit => 80
    t.column :type,               :string, :limit => 6, :default => 'friend'
    t.column :username,           :string, :limit => 80
    t.column :disallow,           :string, :limit => 100
    t.column :allow,              :string, :limit => 100
    t.column :musiconhold,        :string, :limit => 100
    t.column :regseconds,         :integer, :limit => 11, :default => 0
    t.column :ipaddr,             :string, :limit => 15, :default => '0'
    t.column :regexten,           :string, :limit => 80
    t.column :cancallforward,     :string, :limit => 3, :default => 'yes'
    t.column :setvar,             :string, :limit => 100
    #Additional fields for IAX2
    t.column :dbsecret,           :string, :limit => 100
    t.column :inkeys,             :string, :limit => 100
    t.column :outkey,             :string, :limit => 100
    t.column :auth,               :string, :limit => 100
  end
  
  #Asterisk extensions table
  create_table "extensions", :force => true do |t|
    t.column :context,                :string, :limit => 20, :null => false
    t.column :exten,                  :string, :limit => 20, :null => false
    t.column :priority,               :integer, :limit => 4, :default => 0
    t.column :app,                    :string, :limit => 20, :null => false
    t.column :appdata,                :string, :limit => 128, :null => false
  end
  
  #Asterisk queues table
  create_table "callqueues", :force => true do |t|
    t.column :name,                   :string, :limit => 128
    t.column :musiconhold,            :string, :limit => 128
    t.column :announce,               :string, :limit => 128
    t.column :timeout,                :integer, :limit => 11
    t.column :monitor_join,           :boolean
    t.column :monitor_format,         :string, :limit => 128
    t.column :queue_youarenext,       :string, :limit => 128
    t.column :queue_thereare,         :string, :limit => 128
    t.column :queue_callswaiting,     :string, :limit => 128
    t.column :queue_holdtime,         :string, :limit => 128
    t.column :queue_minutes,          :string, :limit => 128
    t.column :queue_seconds,          :string, :limit => 128
    t.column :queue_lessthan,         :string, :limit => 128
    t.column :queue_thankyou,         :string, :limit => 128
    t.column :queue_reporthold,       :string, :limit => 128
    t.column :announce_frequency,     :integer, :limit => 11
    t.column :announce_round_seconds, :integer, :limit => 11
    t.column :announce_holdtime,      :string, :limit => 128
    t.column :retry,                  :integer, :limit => 11
    t.column :wrapuptime,             :integer, :limit => 11
    t.column :maxlen,                 :integer, :limit => 11
    t.column :servicelevel,           :integer, :limit => 11
    t.column :strategy,               :string, :limit => 128
    t.column :joinempty,              :string, :limit => 128
    t.column :leavewhenempty,         :string, :limit => 128
    t.column :eventmemberstatus,      :boolean
    t.column :eventwhencalled,        :boolean
    t.column :reportholdtime,         :boolean
    t.column :memberdelay,            :integer, :limit => 11
    t.column :weight,                 :integer, :limit => 11
    t.column :timeoutrestart,         :boolean
  end

  #Asterisk voicemail extended table
  create_table "voicemailboxes", :force => true do |t|
    t.column :customer_id,            :string, :limit => 11, :null => false
    t.column :context,                :string, :limit => 50, :default => '0'
    t.column :mailbox,                :string, :limit => 11, :null => false
    t.column :password,               :integer, :limit => 5, :default => '0'
    t.column :fullname,               :string, :limit => 150, :null => false
    t.column :email,                  :string, :limit => 50, :null => false
    t.column :pager,                  :string, :limit => 50, :default => ''
    t.column :tz,                     :string, :limit => 10, :default => 'central'
    t.column :attach,                 :string, :limit => 4, :default => 'yes'
    t.column :saycid,                 :string, :limit => 4, :default => 'yes'
    t.column :dialout,                :string, :limit => 10, :default => ''
    t.column :callback,               :string, :limit => 10, :default => ''
    t.column :review,                 :string, :limit => 4, :default => 'no'
    t.column :operator,               :string, :limit => 4, :default => 'no'
    t.column :envelope,               :string, :limit => 4, :default => 'no'
    t.column :sayduration,            :string, :limit => 4, :default => 'no'
    t.column :saydurationm,           :integer, :limit => 4, :default => 1
    t.column :sendvoicemail,          :string, :limit => 4, :default => 'no'
    t.column :delete,                 :string, :limit => 4, :default => 'no'
    t.column :nextaftercmd,           :integer, :limit => 4, :default => 'yes'
    t.column :forcename,              :integer, :limit => 4, :default => 'no'
    t.column :forcegreetings,         :integer, :limit => 4, :default => 'no'
    t.column :hidefromdir,            :string, :limit => 4, :default => 'yes'
    t.column :stamp,                  :timestamp
  end

  #Asterisk voicemail extended table
  create_table "voicemailmessages", :force => true do |t|
    t.column :msgnum,                 :integer, :limit => 11, :default => 0
    t.column :dir,                    :string, :limit => 80, :default => ''
    t.column :context,                :string, :limit => 80, :default => ''
    t.column :macrocontext,           :string, :limit => 80, :default => ''
    t.column :callerid,               :string, :limit => 40, :default => ''
    t.column :origtime,               :string, :limit => 40, :default => ''
    t.column :duration,               :string, :limit => 20, :default => ''
    t.column :mailboxuser,            :string, :limit => 80, :default => ''
    t.column :mailboxcontext,         :string, :limit => 80, :default => ''
    t.column :recording,              :longblob
  end
    
end

Models (app/models/)

app/models/callqueue.rb

class Callqueue < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
end

app/models/device.rb

class Device < ActiveRecord::Base
validates_presence_of :name, :context
validates_uniqueness_of :name
end

app/models/extension.rb

class Extension < ActiveRecord::Base
validates_presence_of :context, :exten, :priority, :app, :appdata
end

app/models/voicemailbox.rb

class Voicemailbox < ActiveRecord::Base
validates_presence_of :customer_id
validates_uniqueness_of :customer_id
end

app/models/voicemessage.rb

class Voicemailmessage < ActiveRecord::Base
end

See Also

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.