Sha256: 5e184c74ee9ad5c85c0342fdd42e8227a5184b3c43f85faccc2001d32203506e

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

require 'sequel'

# check database version

CREATE_TABLE_SCRIPT = File.expand_path("../../../db/create.sql", __FILE__)
print "Checking vmail.db version... "
db = Sequel.connect 'sqlite://vmail.db'
if db.tables.include?(:version) &&
    (r = db[:version].first) &&
    r[:vmail_version] != Vmail::VERSION

  print "Vmail database version is outdated. Recreating.\n"
  `rm vmail.db`
  `sqlite3 vmail.db < #{ CREATE_TABLE_SCRIPT }`
else
  print "OK\n"
end
db.disconnect

if !File.size?('vmail.db')
  puts `sqlite3 vmail.db < #{ CREATE_TABLE_SCRIPT }`
end

DB = Sequel.connect 'sqlite://vmail.db'
puts "Connecting to database"

if DB[:version].count == 0
  DB[:version].insert(:vmail_version => Vmail::VERSION)
end

module Vmail
  class Message < Sequel::Model(:messages)
    set_primary_key :message_id
    one_to_many :labelings
    many_to_many :labels, :join_table => 'labelings'
  end
end

if DB[:version].count == 0
  DB[:version].insert(:vmail_version => Vmail::VERSION)
end


module Vmail
  class Message < Sequel::Model(:messages)
    set_primary_key :message_id
    one_to_many :labelings
    many_to_many :labels, :join_table => 'labelings'
  end

  class Label < Sequel::Model(:labels)
    set_primary_key :label_id
    one_to_many :labelings
    many_to_many :messages, :join_table => 'labelings'
  end

  class Labeling < Sequel::Model(:labelings)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vmail-2.9.11 lib/vmail/database.rb
vmail-2.9.10 lib/vmail/database.rb
vmail-2.9.9 lib/vmail/database.rb
vmail-2.9.8 lib/vmail/database.rb
vmail-2.9.7 lib/vmail/database.rb
vmail-2.9.6 lib/vmail/database.rb
vmail-2.9.5 lib/vmail/database.rb