Class: ModSpox::Migrations::InitializeModels

Inherits:
Sequel::Migration
  • Object
show all
Defined in:
lib/mod_spox/migrations/001_initialize_models.rb

Instance Method Summary collapse

Instance Method Details

#downObject



106
107
108
109
110
111
112
# File 'lib/mod_spox/migrations/001_initialize_models.rb', line 106

def down
    [:nick_modes, :nick_groups, :nick_channels, :channel_modes, :auth_groups,
     :triggers, :signatures, :settings, :servers, :configs, :groups, :auths,
     :channels, :nicks].each do |table|
        Database.db.drop_table(table) if Database.db.table_exists?(table)
    end
end

#upObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/mod_spox/migrations/001_initialize_models.rb', line 5

def up
    Database.db << "SET FOREIGN_KEY_CHECKS = 0" if Database.type == :mysql
    Database.db.create_table(:nicks) do
        primary_key :id, :null => false
        varchar :nick, :null => false, :unique => true
        varchar :username
        varchar :real_name
        varchar :address
        varchar :host
        varchar :source
        timestamp :connected_at
        varchar :connected_to
        integer :seconds_idle
        boolean :visible, :null => false, :default => false
        boolean :away, :null => false, :default => false
        boolean :botnick, :null => false, :default => false
    end unless Database.db.table_exists?(:nicks)
    Database.db.create_table(:channels) do
        primary_key :id, :null => false
        varchar :name, :null => false, :unique => true
        varchar :password
        boolean :autojoin, :null => false, :default => false
        varchar :topic
        boolean :quiet, :null => false, :default => false
        boolean :parked, :null => false, :default => false
    end unless Database.db.table_exists?(:channels)
    Database.db.create_table(:auths) do
        primary_key :id, :null => false
        varchar :password
        boolean :services, :null => false, :default => false
        varchar :mask, :unique => true, :default => nil
        boolean :authed, :null => false, :default => false
        foreign_key :nick_id, :table => :nicks, :unique => true, :null => false, :key => :id
    end unless Database.db.table_exists?(:auths)
    Database.db.create_table(:groups) do
        primary_key :id, :null => false
        varchar :name, :null => false, :unique => true
    end unless Database.db.table_exists?(:groups)
    Database.db.create_table(:configs) do
        primary_key :id, :null => false
        varchar :name, :null => false, :unique => true
        varchar :value
    end unless Database.db.table_exists?(:configs)
    Database.db.create_table(:servers) do
        primary_key :id, :null => false
        varchar :host, :null => false
        integer :port, :null => false, :default => 6667
        integer :priority, :null => false, :default => 0
        boolean :connected, :null => false, :default => false
        index [:host, :port], :unique => true
    end unless Database.db.table_exists?(:servers)
    Database.db.create_table(:settings) do
        primary_key :id, :null => false
        varchar :name, :null => false, :unique => true
        text :value
    end unless Database.db.table_exists?(:settings)
    Database.db.create_table(:signatures) do
        primary_key :id, :null => false
        varchar :signature, :null => false
        varchar :params
        foreign_key :group_id, :table => :groups, :default => nil, :key => :id
        varchar :method, :null => false
        varchar :plugin, :null => false
        varchar :description
        varchar :requirement, :null => false, :default => 'both'
    end unless Database.db.table_exists?(:signatures)
    Database.db.create_table(:triggers) do
        primary_key :id, :null => false
        varchar :trigger, :unique => true, :null => false
        boolean :active, :null => false, :default => false
    end unless Database.db.table_exists?(:triggers)
    Database.db.create_table(:auth_groups) do
        foreign_key :group_id, :table => :groups, :null => false, :key => :id
        foreign_key :auth_id, :table => :auths, :null => false, :key => :id
        primary_key [:group_id, :auth_id]
    end unless Database.db.table_exists?(:auth_groups)
    Database.db.create_table(:channel_modes) do
        primary_key :id, :null => false
        varchar :mode, :null => false
        foreign_key :channel_id, :table => :channels, :unique => true, :null => false, :key => :id
    end unless Database.db.table_exists?(:channel_modes)
    Database.db.create_table(:nick_channels) do
        foreign_key :nick_id, :table => :nicks, :null => false, :key => :id
        foreign_key :channel_id, :table => :channels, :null => false, :key => :id
        primary_key [:nick_id, :channel_id]
    end unless Database.db.table_exists?(:nick_channels)
    Database.db.create_table(:nick_groups) do
        foreign_key :group_id, :table => :groups, :null => false, :key => :id
        foreign_key :nick_id, :table => :nicks, :null => false, :key => :id
        primary_key [:nick_id, :group_id]
    end unless Database.db.table_exists?(:nick_groups)
    Database.db.create_table(:nick_modes) do
        primary_key :id, :null => false
        varchar :mode, :null => false
        foreign_key :nick_id, :table => :nicks, :null => false, :key => :id
        foreign_key :channel_id, :table => :channels, :key => :id
        index [:nick_id, :channel_id]
    end unless Database.db.table_exists?(:nick_modes)
    Database.db << "SET FOREIGN_KEY_CHECKS = 1" if Database.type == :mysql
end