Class: Mysql2psql::Config
- Inherits:
-
ConfigBase
- Object
- ConfigBase
- Mysql2psql::Config
- Defined in:
- lib/mysql2psql/config.rb
Instance Attribute Summary
Attributes inherited from ConfigBase
Class Method Summary collapse
-
.template(options = {}) ⇒ Object
Returns template file text given
options
hash which may include: :to_filename - default: nil :include_tables - default: [] :exclude_tables - default: [] :suppress_data - default: false :suppress_ddl - default: false :suppress_sequence_update - default: false :suppress_indexes - default: false :force_truncate - default: false :use_timezones - default: false.
Instance Method Summary collapse
-
#initialize(configfilepath, generate_default_if_not_found = true) ⇒ Config
constructor
A new instance of Config.
- #reset_configfile(filepath) ⇒ Object
Methods inherited from ConfigBase
Constructor Details
#initialize(configfilepath, generate_default_if_not_found = true) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mysql2psql/config.rb', line 7 def initialize(configfilepath, generate_default_if_not_found = true) unless File.exists?(configfilepath) reset_configfile(configfilepath) if generate_default_if_not_found if File.exists?(configfilepath) raise Mysql2psql::ConfigurationFileInitialized.new("\n No configuration file found. A new file has been initialized at: #{configfilepath} Please review the configuration and retry..\n\n\n") else raise Mysql2psql::ConfigurationFileNotFound.new("cannot load config file #{configfilepath}") end end super(configfilepath) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mysql2psql::ConfigBase
Class Method Details
.template(options = {}) ⇒ Object
Returns template file text given options
hash which may include: :to_filename - default: nil :include_tables - default: [] :exclude_tables - default: [] :suppress_data - default: false :suppress_ddl - default: false :suppress_sequence_update - default: false :suppress_indexes - default: false :force_truncate - default: false :use_timezones - default: false
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/mysql2psql/config.rb', line 40 def self.template(={}) configtext = <<EOS mysql: hostname: localhost port: 3306 socket: username: mysql2psql password: database: mysql2psql_test destination: # if file is given, output goes to file, else postgres file: #{ [:to_filename] || ''} postgres: hostname: localhost port: 5432 username: mysql2psql password: database: mysql2psql_test # if tables is given, only the listed tables will be converted. leave empty to convert all tables. #tables: #- table1 #- table2 EOS include_tables = [:include_tables] || [] if include_tables.length>0 configtext += "\ntables:\n" include_tables.each do |t| configtext += "- #{t}\n" end end configtext += <<EOS # if exclude_tables is given, exclude the listed tables from the conversion. #exclude_tables: #- table3 #- table4 EOS exclude_tables = [:exclude_tables] || [] if exclude_tables.length>0 configtext += "\nexclude_tables:\n" exclude_tables.each do |t| configtext += "- #{t}\n" end end if ![:suppress_data].nil? configtext += <<EOS # if suppress_data is true, only the schema definition will be exported/migrated, and not the data suppress_data: #{[:suppress_data]} EOS end if ![:suppress_ddl].nil? configtext += <<EOS # if suppress_ddl is true, only the data will be exported/imported, and not the schema suppress_ddl: #{[:suppress_ddl]} EOS end if ![:suppress_sequence_update].nil? configtext += <<EOS # if suppress_sequence_update is true, the sequences for serial (auto-incrementing) columns # will not be update to the current maximum value of that column in the database # if suppress_ddl is not set to true, then this option is implied to be false as well (unless overridden here) suppress_sequence_update: #{[:suppress_sequence_update]} EOS end if ![:force_truncate].nil? configtext += <<EOS # if force_truncate is true, forces a table truncate before table loading force_truncate: #{[:force_truncate]} EOS end if ![:use_timezones].nil? configtext += <<EOS # if use_timezones is true, timestamp/time columns will be created in postgres as "with time zone" # rather than "without time zone" use_timezones: #{[:use_timezones]} EOS end if ![:suppress_indexes].nil? configtext += <<EOS # if suppress_indexes is true, indexes will not be exported/migrated suppress_indexes: #{[:suppress_indexes]} EOS end configtext end |
Instance Method Details
#reset_configfile(filepath) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/mysql2psql/config.rb', line 22 def reset_configfile(filepath) file = File.new(filepath,'w') self.class.template.each_line do | line| file.puts line end file.close end |