porter 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,7 +18,7 @@ More on the Capistrano Multistage Extension:
18
18
 
19
19
  ## Installation
20
20
 
21
- * Add gem "porter", "~> 1.1.0" to your Gemfile
21
+ * Add gem "porter", "~> 1.2.0" to your Gemfile
22
22
  * Run: bundle install
23
23
  * Run: rails g porter
24
24
  * Add require "porter/capistrano" to your config/deploy.rb
@@ -34,7 +34,17 @@ This will do the following:
34
34
 
35
35
  * A mysqldump command will be remotely issued (via Capistrano) to the remote server, saving the result as a compressed (gz) file
36
36
  * The database backup file from the server will be retrieved (via scp) and decompressed
37
- * The database for the environment you are running the task in will be dropped, recreated, and restored from the backup
37
+ * The database for the environment you are running the task in will be dropped, recreated, the schema will be reloaded from the stage's schema.rb and the mysqldump will be restored
38
+
39
+ Note: Since the schema is reloaded once the database is recreated, but before the backup is restored, you should end up with tables that match the remote stage minus the data form the ignored tables.
40
+
41
+ #### Optionally omit specific tables from the MySQL dump
42
+
43
+ Using the ignore_tables attribute in the porter_config.yml file, you can specify any number of tables to ignore in the mysqldump that is executed on the remote server. This setting is available for each stage (server) you define in the config file. Table names should be separated by spaces.
44
+
45
+ You can override the ignore_tables setting as needed when executing the porter:db task with an environment variable:
46
+
47
+ $ bundle exec cap production porter:db IGNORE_TABLES="delayed_jobs versions"
38
48
 
39
49
  ### Synchronize a remote server's filesystem-stored assets to your local filesystem
40
50
 
@@ -48,7 +58,7 @@ This will do the following:
48
58
 
49
59
  The MIT License
50
60
 
51
- Copyright (c) 2010-2011 Kenny Johnston
61
+ Copyright (c) 2010-2012 Kenny Johnston
52
62
 
53
63
  Permission is hereby granted, free of charge, to any person obtaining a copy
54
64
  of this software and associated documentation files (the "Software"), to deal
@@ -1,9 +1,11 @@
1
1
  # Config file for porter gem
2
2
 
3
3
  production:
4
+ ignore_tables:
4
5
  asset_dirs: public/system
5
6
  rsync_options: --verbose --progress --stats --recursive --times --compress --delete
6
7
 
7
- # staging:
8
- # asset_dirs: public/system
9
- # rsync_options: --verbose --progress --stats --recursive --times --compress --delete
8
+ staging:
9
+ ignore_tables:
10
+ asset_dirs: public/system
11
+ rsync_options: --verbose --progress --stats --recursive --times --compress --delete
@@ -10,20 +10,41 @@ if instance = Capistrano::Configuration.instance
10
10
  puts "Connecting to #{domain} as #{user}..."
11
11
 
12
12
  puts "Reading database.yml on #{domain}..."
13
- database_yml = ""
13
+ db_yml = ""
14
14
  run "cat #{deploy_to}/current/config/database.yml" do |channel, stream, data|
15
- database_yml << data
15
+ db_yml << data
16
+ end
17
+ db_config = YAML::load(db_yml)[stage.to_s]
18
+ db_name = db_config["database"]
19
+ db_username = db_config["username"]
20
+ db_password = db_config["password"]
21
+ db_credentials = "--user=#{db_username} --password=#{db_password} "
22
+
23
+ puts "Reading schema.rb on #{domain}..."
24
+ schema_rb = ""
25
+ run "cat #{deploy_to}/current/db/schema.rb" do |channel, stream, data|
26
+ schema_rb << data
27
+ end
28
+ schema_file = "porter_schema.rb"
29
+ File.open(schema_file, "w") do |f|
30
+ f.puts schema_rb
16
31
  end
17
32
 
18
- config = YAML::load(database_yml)[stage.to_s]
19
- database = config["database"]
20
- username = config["username"]
21
- password = config["password"]
33
+ porter_config = YAML::load_file("config/porter_config.yml")
34
+
35
+ if ENV["IGNORE_TABLES"]
36
+ tables_to_ignore = ENV["IGNORE_TABLES"].split(" ")
37
+ elsif stage_config = porter_config[stage.to_s] and stage_config["ignore_tables"]
38
+ tables_to_ignore = stage_config["ignore_tables"].split(" ")
39
+ end
40
+ ignore_tables = (tables_to_ignore || []).map { |table_name| "--ignore-table=#{db_name}.#{table_name.strip}" }.join(" ")
22
41
 
23
- puts "Creating compressed backup of #{database} database on #{domain}..."
24
- run "mysqldump --user=#{username} --password=#{password} #{database} | gzip > ~/#{database}.sql.gz"
42
+ # Run mysqldump on the stage
43
+ puts "Creating compressed backup of #{db_name} database on #{domain}..."
44
+ run "mysqldump #{db_credentials} #{db_name} #{ignore_tables} | gzip > ~/#{db_name}.sql.gz"
25
45
 
26
- system "rake porter:db DOMAIN=#{domain} DATABASE=#{database} --trace"
46
+ # Issue rake task to restore the database backup
47
+ system "rake porter:db DOMAIN=#{domain} DATABASE=#{db_name} SCHEMA=#{schema_file}"
27
48
  end
28
49
 
29
50
  task :assets do
@@ -1,3 +1,3 @@
1
1
  module Porter
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -33,6 +33,10 @@ namespace :porter do
33
33
  puts "Creating database: " + destintation_database
34
34
  Rake::Task["db:create"].execute
35
35
 
36
+ puts "Loading schema..."
37
+ Rake::Task["db:schema:load"].execute
38
+ rm "#{root}/porter_schema.rb"
39
+
36
40
  puts "Restoring database from backup..."
37
41
  mysql_version = `which mysql`.empty? ? "mysql5" : "mysql"
38
42
  cmd = [mysql_version]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: porter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-12-07 00:00:00.000000000Z
13
+ date: 2012-03-08 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: capistrano
17
- requirement: &2223799140 !ruby/object:Gem::Requirement
17
+ requirement: &2198798880 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2223799140
25
+ version_requirements: *2198798880
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: capistrano-ext
28
- requirement: &2223798140 !ruby/object:Gem::Requirement
28
+ requirement: &2198798380 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2223798140
36
+ version_requirements: *2198798380
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rake
39
- requirement: &2223797360 !ruby/object:Gem::Requirement
39
+ requirement: &2198797920 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 0.8.7
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2223797360
47
+ version_requirements: *2198797920
48
48
  description: Capistrano and Rake tasks for cloning production and/or staging databases
49
49
  and assets to development.
50
50
  email: