Skip to content
Browse files

Replacing smailr setup with Sequel database migrations, so we are abl…

…e to shipupgrades in the future.

 * Adding migration files
 * Updated documentation
 * Bumping gem version
  • Loading branch information...
1 parent b389284 commit d1794a95cae978618ae85b50e1f82aab5d05450f @sts committed
Showing with 84 additions and 62 deletions.
  1. +2 −2 README.md
  2. +11 −22 bin/smailr
  3. +3 −5 lib/smailr.rb
  4. +8 −0 migrations/001_domains.rb
  5. +12 −0 migrations/002_mailboxes.rb
  6. +13 −0 migrations/003_aliases.rb
  7. +12 −0 migrations/004_dkims.rb
  8. +23 −33 smailr.gemspec
View
4 README.md
@@ -27,10 +27,10 @@ Add a user which will own the mails and is used for the LDA
mkdir /srv/mail/users
chown -R vmail:vmail /srv/mail
-Run the setup command to initialize the smailr database in
+Run the setup command to initialize the smailr database
# Creates /etc/exim4/smailr.sqlite
- smailr setup
+ smailr migrate
Add a domain and an user to your database using the commands listed below.
View
33 bin/smailr
@@ -87,29 +87,18 @@ command :rm do |c|
end
end
-command :setup do |c|
- c.syntax = 'smailr setup'
- c.summary = 'Initialize the database.'
- c.action do |args, options|
- DB.create_table :domains do
- primary_key :id
- column :fqdn, :string, :unique => true
- end
-
- DB.create_table :mailboxes do
- primary_key :id
- foreign_key :domain_id
- column :localpart, :string, :required => true
- column :password, :string, :required => true
- index [:domain_id, :localpart], :unique => true
- end
+command :migrate do |c|
+ c.syntax = 'smailr migrate [options]'
+ c.summary = 'Run database migrations'
+ c.option '--to VERSION', String, 'Migrate the database to a specifict version.'
+ c.action do |args,options|
+ require 'sequel/extensions/migration'
+ raise "Database not configured" unless DB
- DB.create_table :aliases do
- primary_key :id
- foreign_key :mailbox_id
- column :address, :string, :required => true
- index [:address, :mailbox_id], :unique => true
- index :address
+ if options.version.nil?
+ Sequel::Migrator.apply(DB, 'migrations' )
+ else
+ Sequel::Migrator.apply(DB, 'migrations', :target => options.version.to_i)
end
end
end
View
8 lib/smailr.rb
@@ -1,8 +1,6 @@
require 'rubygems'
-require 'bundler/setup'
-
-Bundler.require(:default)
-
+require 'sqlite3'
+require 'sequel'
require 'commander/import'
module Smailr
@@ -11,6 +9,6 @@ module Smailr
autoload :Mailbox, 'smailr/mailbox'
autoload :Alias, 'smailr/alias'
- program :version, '0.1'
+ program :version, '0.2.0'
program :description, 'Simple MAIL mangaR - Virtual mail hosting management from the CLI'
end
View
8 migrations/001_domains.rb
@@ -0,0 +1,8 @@
+Sequel.migration do
+ change do
+ create_table :domains do
+ primary_key :id
+ String :fqdn, :unique => true
+ end
+ end
+end
View
12 migrations/002_mailboxes.rb
@@ -0,0 +1,12 @@
+Sequel.migration do
+ change do
+ create_table :mailboxes do
+ primary_key :id
+ foreign_key :domain_id
+ String :localpart, :required => true
+ String :password, :required => true
+
+ index [:domain_id, :localpart], :unique => true
+ end
+ end
+end
View
13 migrations/003_aliases.rb
@@ -0,0 +1,13 @@
+Sequel.migration do
+ change do
+ create_table :aliases do
+ primary_key :id
+ foreign_key :mailbox_id
+ String :address, :required => true
+
+ index [:address, :mailbox_id], :unique => true
+ index :address
+ end
+ end
+end
+
View
12 migrations/004_dkims.rb
@@ -0,0 +1,12 @@
+Sequel.migration do
+ change do
+ create_table :dkims do
+ primary_key :id
+ foreign_key :domain_id
+ String :private_key, :required => true
+ String :public_key, :required => true
+ String :mode, :required => true
+ Boolean :testing, :required => true
+ end
+ end
+end
View
56 smailr.gemspec
@@ -1,7 +1,9 @@
+# -*- encoding: utf-8 -*-
+
Gem::Specification.new do |s|
s.name = 'smailr'
- s.version = '0.0.1'
- s.date = '2012-04-24'
+ s.version = '0.2.0'
+ s.date = '2012-04-26'
s.authors = 'Stefan Schlesinger'
s.email = 'sts@ono.at'
s.homepage = 'http://github.com/sts/smailr'
@@ -9,42 +11,30 @@ Gem::Specification.new do |s|
s.description = 'Smailr is a CLI tool which lets you manage your Exim/Dovecot setup
from the shell. It currently uses SQLite as a backend.'
+ s.has_rdoc = false
+ s.files = Dir.glob("{bin,lib,contrib}/**/*")
+
+ s.bindir = 'bin'
+ s.executables << 'smailr'
+
+ s.add_dependency 'commander'
+ s.add_dependency 'sqlite3'
+ s.add_dependency 'sequel'
+
+ s.requirements << 'Exim'
+ s.requirements << 'Dovecot'
+ s.requirements << 'Debian'
+
s.post_install_message = "
-SMAILR ////////////////////////////////////////////////
+SMAILR /////////////////////////////////////////////////////////////////
-To finish the installation copy the example Exim and
-Dovecot configuration files from the contrib directory.
+ To finish the installation copy the example Exim and Dovecot
+ configuration files from the contrib directory and run
+ 'smailr migrate' to initialize the database.
-///////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////// ///////
"
- s.requirements << 'Exim'
- s.requirements << 'Dovecot'
- s.requirements << 'Debian'
-
- s.bindir = 'bin'
- s.executables << 'smailr'
-
- s.files = %w[
- bin
- bin/smailr
- contrib
- contrib/dovecot-sql.conf
- contrib/dovecot.conf
- contrib/exim4.conf
- Gemfile
- Gemfile.lock
- lib
- lib/smailr
- lib/smailr/alias.rb
- lib/smailr/domain.rb
- lib/smailr/mailbox.rb
- lib/smailr/model.rb
- lib/smailr.rb
- README.md
- smailr.gemspec
- ]
-
end

0 comments on commit d1794a9

Please sign in to comment.
Something went wrong with that request. Please try again.