Method: Mysql2psql::Config.template

Defined in:
lib/mysql2psql/config.rb

.template(to_filename = nil, include_tables = [], exclude_tables = [], supress_data = false, supress_ddl = false, force_truncate = false) ⇒ Object



30
31
32
33
34
35
36
37
38
39
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
# File 'lib/mysql2psql/config.rb', line 30

def self.template(to_filename = nil, include_tables = [], exclude_tables = [], supress_data = false, supress_ddl = false, force_truncate = false)
  configtext = <<EOS
mysql:
 hostname: localhost
 port: 3306
 socket: /tmp/mysql.sock
 username: mysql2psql
 password: 
 database: mysql2psql_test

destination:
 # if file is given, output goes to file, else postgres
 file: #{ to_filename ? 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
  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
  if exclude_tables.length>0
    configtext += "\nexclude_tables:\n"
    exclude_tables.each do |t|
      configtext += "- #{t}\n"
    end
  end
  if !supress_data.nil?
    configtext += <<EOS

# if supress_data is true, only the schema definition will be exported/migrated, and not the data
supress_data: #{supress_data}
EOS
  end
  if !supress_ddl.nil?
    configtext += <<EOS

# if supress_ddl is true, only the data will be exported/imported, and not the schema
supress_ddl: #{supress_ddl}
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
  configtext
end