pg_migrator 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36d84444aad6de2cdd270d988eed37ef801345b1
4
- data.tar.gz: 620a5c79de147d72ac8f5f457154d67849168fe8
3
+ metadata.gz: 29643f07a4823e69084a522fc53d3fad7c7e74a8
4
+ data.tar.gz: f88595756fed4b1365637f875a1a30fa3e3700d5
5
5
  SHA512:
6
- metadata.gz: 6efb9334f109eaa4897c456483c83f43245af196c9bd7d6d31e1aeb5f8030d831b85621d76983eec6a14d8c96b4a0d313cb3046eb00f4de2c2e60b0d89a6f60b
7
- data.tar.gz: a68e4ec38d826b20502bb44fb200c2faafbd90776238882e18ba61ee21c01cab3d37bfe797c7de6fe4a9da48b93d9175365b15c264d4d3202f9e4d25f38cf049
6
+ metadata.gz: 3d9900b17c50064d7211a7606b14fe1f6ba507c18b21d5d98151991d3344a767c81cd1b74370a4a592795810068c47ca833fd377ebb618cb137e6eec982dc48f
7
+ data.tar.gz: e9720f10fc0ec7b73149247a0c98253c4ac2da188b88dcb67951c8356705137ec221023d4dd09e9a22c4fd6929750c17b5c39cab3d6da81c40682dd973fb3b83
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  PG Migrator
2
2
  ===========
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/pg_migrator.svg)](https://badge.fury.io/rb/pg_migrator)
5
+ [![Build Status](https://travis-ci.org/pyer/pg_migrator.svg?branch=master)](https://travis-ci.org/pyer/pg_migrator)
6
+
4
7
  * This tool provides a set of Rake tasks to apply changes on different Postgres environments.
5
8
  * Every change, upgrade or rollback, is versionned.
6
9
  * Each environment is described by a configuration file.
@@ -44,18 +47,30 @@ Configuration
44
47
  Migrations script files
45
48
  -----------------------
46
49
 
47
- Migration SQL scripts are stored in a directory compliant with the pattern configuration parameter.
50
+ Migration SQL scripts are stored in a directory compliant with two configuration parameters, upgrade and downgrade.
48
51
  Default directory is 'migrations'.
49
- Each file initialize two variables '@up' and '@down' used to upgrade and rollback the database.
50
- Version number is the first 3 digits of the script file name.
51
- Script file names must be compliant with the pattern parameter and the 'xyz_comment.rb' format where xyz is the version number from '001' to '999'.
52
- An empty newly created database is in version '000'.
52
+ Upgrade and downgrade SQL script file names must be compliant with upgrade and downgrade parameters in the configuration file.
53
+ Version number is text between the last character '/' and next character '\_' in script file name.
54
+ An empty newly created database is in version set by version0 parameter.
53
55
  Several files can have the same version number.
54
56
 
55
- Example: 'migrations/002_add_id_3_in_tablename.rb'
57
+ Version number can be 000, 0.1.1, 0.09, 1.2a or any other text.
58
+ Next version number is given by #next method of String object.
59
+ Beware, next version of 1.9 is 2.0 and next version of 1.09 is 1.10
60
+
61
+ Example: version 0.02
62
+
63
+ * Update parameter
64
+ `upgrade = migrations/\*_up_\*.sql`
56
65
 
57
- @up = "INSERT INTO tablename (id, caption) VALUES (3,'something');"
58
- @down = "DELETE FROM tablename WHERE id = 3;"
66
+ * Script file: migrations/0.02_up_add_id_3_in_tablename.sql
67
+ `INSERT INTO tablename (id, caption) VALUES (3,'something');`
68
+
69
+ * Downgrade parameter
70
+ `downgrade = migrations/\*_down_\*.sql`
71
+
72
+ * Script file: migrations/0.02_down_add_id_3_in_tablename.sql
73
+ `DELETE FROM tablename WHERE id = 3;`
59
74
 
60
75
 
61
76
  Database requirements
@@ -64,7 +79,8 @@ Database requirements
64
79
  * For now, database engine MUST BE Postgres.
65
80
  * The database MUST NOT have a table called 'migrations'.
66
81
  * Database version is the version of the last database upgrade, stored in the 'migrations' table.
67
- * An empty database is in version '000'.
82
+ * Downgrade are not logged in migrations table.
83
+
68
84
 
69
85
  Options
70
86
  -------
data/Rakefile CHANGED
@@ -33,7 +33,13 @@ task install: 'build' do
33
33
  gi.install
34
34
  end
35
35
 
36
- rakefiles = Rake::FileList['tasks/*.rake']
37
- rakefiles.each do |file|
38
- load "#{file}"
36
+ # load pg_migrator rake files for local dev and test
37
+ begin
38
+ Gem::Specification.find_by_name('pg_migrator')
39
+ require 'pg_migrator'
40
+ PGMigrator.new
41
+ rescue Gem::LoadError
42
+ puts "Warning: Could not find 'pg_migrator'"
39
43
  end
44
+
45
+ task default: :test
data/lib/db.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # coding: utf-8
2
- require 'config'
3
2
  require 'postgres'
4
3
 
5
4
  # Database managment
@@ -44,7 +43,7 @@ class DB
44
43
  def self.databases(config)
45
44
  dbs = []
46
45
  pg = Postgres.new(config, 'postgres')
47
- dbs = pg.execute('SELECT * FROM pg_database ORDER BY datname;') if pg_ok?
46
+ dbs = pg.execute('SELECT * FROM pg_database ORDER BY datname;') if pg.ok?
48
47
  pg.finish
49
48
  dbs
50
49
  end
data/lib/pg_migrator.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- #
2
+
3
3
  # Load rake tasks
4
4
  class PGMigrator
5
5
  def initialize
data/pg_migrator.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'pg_migrator'
5
- s.version = '1.0.1'
5
+ s.version = '1.0.2'
6
6
  s.author = 'Pierre BAZONNARD'
7
7
  s.email = ['pierre.bazonnard@gmail.com']
8
8
  s.homepage = 'https://github.com/pyer/pg_migrator'
data/tasks/config.rake CHANGED
@@ -1,7 +1,6 @@
1
1
  # coding: utf-8
2
2
  require 'rake'
3
- require 'config'
4
-
3
+ require_relative '../lib/config.rb'
5
4
  @config = nil
6
5
 
7
6
  task :load_config do
@@ -31,5 +30,3 @@ task environments: :load_config do
31
30
  puts file.split('/')[1]
32
31
  end
33
32
  end
34
-
35
- task default: :config
data/tasks/db.rake CHANGED
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
- require 'db'
2
+ require_relative '../lib/db.rb'
3
3
 
4
4
  desc 'Show the current database version'
5
5
  task version: [:load_config] do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_migrator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre BAZONNARD
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-30 00:00:00.000000000 Z
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake