Skip to content

Commit 4ea387c

Browse files
committed
added campaign models and migrations
1 parent 9ac95e6 commit 4ea387c

6 files changed

+73
-0
lines changed

migrations/011_create_campaigns.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2008-2009 The Rubyists, LLC (effortless systems) <[email protected]>
2+
# Distributed under the terms of the MIT license.
3+
# The full text can be found in the LICENSE file included with this software
4+
#
5+
Class.new Sequel::Migration do
6+
def up
7+
create_table(:campaigns) do
8+
primary_key :id
9+
String :name
10+
String :description
11+
timestamp :timestamp, :default => :now.sql_function
12+
end unless TinyDialer.db.tables.include? :campaigns
13+
end
14+
15+
def down
16+
remove_table(:campaigns) if TinyDialer.db.tables.include? :campaigns
17+
end
18+
end

migrations/012_create_lists.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2008-2009 The Rubyists, LLC (effortless systems) <[email protected]>
2+
# Distributed under the terms of the MIT license.
3+
# The full text can be found in the LICENSE file included with this software
4+
#
5+
Class.new Sequel::Migration do
6+
def up
7+
create_table(:lists) do
8+
primary_key :id
9+
String :name
10+
String :description
11+
Integer :start_time
12+
Integer :stop_time
13+
timestamp :timestamp, :default => :now.sql_function
14+
foreign_key :campaign_id, :campaigns
15+
end unless TinyDialer.db.tables.include? :lists
16+
end
17+
18+
def down
19+
remove_table(:lists) if TinyDialer.db.tables.include? :lists
20+
end
21+
end
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2008-2009 The Rubyists, LLC (effortless systems) <[email protected]>
2+
# Distributed under the terms of the MIT license.
3+
# The full text can be found in the LICENSE file included with this software
4+
#
5+
Class.new Sequel::Migration do
6+
def up
7+
alter_table :leads do
8+
add_foreign_key :list_id, :lists
9+
add_column :start_time, Integer
10+
add_column :stop_time, Integer
11+
end
12+
end
13+
14+
def down
15+
alter_table :leads do
16+
drop_column :list_id
17+
drop_column :start_time
18+
drop_column :stop_time
19+
end
20+
end
21+
end

model/campaign.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module TinyDialer
2+
class Campaign < Sequel::Model
3+
one_to_many :lists
4+
end
5+
end

model/init.rb

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
require TinyDialer::LIBROOT/:tiny_dialer/:db
66
raise "No DB available" unless TinyDialer.db
77

8+
require_relative 'campaign'
9+
require_relative 'list'
810
require_relative 'lead'
911
require_relative 'zip'
1012
require_relative 'state'

model/list.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module TinyDialer
2+
class List < Sequel::Model
3+
many_to_one :campaign
4+
one_to_many :leads
5+
end
6+
end

0 commit comments

Comments
 (0)