Module: TDP
- Defined in:
- lib/tdp.rb
Overview
Tiny Database Patcher.
Defined Under Namespace
Classes: ContradictionError, DAO, DuplicateError, Engine, MismatchError, NotAppliedError, NotConfiguredError, Patch, PatchSet
Class Method Summary collapse
-
.execute(db, paths = []) {|engine| ... } ⇒ Object
Main entrypoint of TDP package.
-
.patch_file?(filename) ⇒ Boolean
Returns true if argument is a valid file name of a patch.
-
.permanent_patch_file?(filename) ⇒ Boolean
Returns true if argument is a valid file name of a permanent patch.
-
.volatile_patch_file?(filename) ⇒ Boolean
Returns true if argument is a valid file name of a volatile patch.
Class Method Details
.execute(db, paths = []) {|engine| ... } ⇒ Object
Main entrypoint of TDP package.
Initializes an Engine with given database details and schema files locations and then calls the given block passing engine as a parameter.
- db
-
must be one of:
-
instance of Sequel::Database class
-
database URL that can be passed to Sequel.connect()
paths must be an array of names of .sql files and directories containing those files
502 503 504 505 506 507 |
# File 'lib/tdp.rb', line 502 def self.execute(db, paths = []) engine = Engine.new(db) paths.each { |x| engine << x } engine.bootstrap yield engine end |
.patch_file?(filename) ⇒ Boolean
Returns true if argument is a valid file name of a patch.
To qualify for a patch, file name must end with “.sql” extension.
484 485 486 |
# File 'lib/tdp.rb', line 484 def self.patch_file?(filename) filename.end_with?('.sql') end |
.permanent_patch_file?(filename) ⇒ Boolean
Returns true if argument is a valid file name of a permanent patch.
To qualify for a permanent patch, file name must start with a number and end with “.sql” extension. E.g. 001-initial-schema.sql or 201611001_add_accounts_table.sql
461 462 463 |
# File 'lib/tdp.rb', line 461 def self.permanent_patch_file?(filename) /^\d+.*\.sql$/ =~ filename end |
.volatile_patch_file?(filename) ⇒ Boolean
Returns true if argument is a valid file name of a volatile patch.
To qualify for a volatile patch, file name must end with “.sql” exception and NOT start with a number (otherwise it’d qualify for permanent patch instead). E.g. views.sql or stored-procedures.sql
474 475 476 |
# File 'lib/tdp.rb', line 474 def self.volatile_patch_file?(filename) /^[^\d]+.*\.sql$/ =~ filename end |