Class: CreateSchema

Inherits:
Sequel::Migration
  • Object
show all
Defined in:
lib/larch/db/migrate/001_create_schema.rb

Instance Method Summary collapse

Instance Method Details

#downObject



2
3
4
# File 'lib/larch/db/migrate/001_create_schema.rb', line 2

def down
  drop_table :accounts, :mailboxes, :messages
end

#upObject



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
# File 'lib/larch/db/migrate/001_create_schema.rb', line 6

def up
  create_table :accounts do
    primary_key :id
    text :hostname, :null => false
    text :username, :null => false

    unique [:hostname, :username]
  end

  create_table :mailboxes do
    primary_key :id
    foreign_key :account_id, :table => :accounts
    text :name, :null => false
    text :delim, :null => false
    text :attr, :null => false, :default => ''
    integer :subscribed, :null => false, :default => 0
    integer :uidvalidity
    integer :uidnext

    unique [:account_id, :name, :uidvalidity]
  end

  create_table :messages do
    primary_key :id
    foreign_key :mailbox_id, :table => :mailboxes
    integer :uid, :null => false
    text :guid, :null => false
    text :message_id
    integer :rfc822_size, :null => false
    integer :internaldate, :null => false
    text :flags, :null => false, :default => ''

    index :guid
    unique [:mailbox_id, :uid]
  end
end