Method: DataDuck::Commands.quickstart

Defined in:
lib/dataduck/commands.rb

.quickstartObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/dataduck/commands.rb', line 177

def self.quickstart
  puts "Welcome to DataDuck!"
  puts "This quickstart wizard will help you set up DataDuck."

  puts "What is your work email address?"
  email = STDIN.gets.strip
  self.quickstart_register_email(email)

  puts "What kind of database would you like to source from?"
  db_type = prompt_choices([
      [:mysql, "MySQL"],
      [:postgresql, "PostgreSQL"],
      [:other, "other"],
  ])

  if db_type == :other
    puts "You've selected 'other'. Unfortunately, those are the only choices supported at the moment. Contact us at DataDuckETL.com to request support for your database."
    exit
  end

  puts "Enter the source hostname:"
  source_host = STDIN.gets.strip

  puts "Enter the name of the database when connecting to #{ source_host }:"
  source_database = STDIN.gets.strip

  puts "Enter the source's port:"
  source_port = STDIN.gets.strip.to_i

  puts "Enter the username:"
  source_username = STDIN.gets.strip

  puts "Enter the password:"
  source_password = STDIN.noecho(&:gets).chomp

  db_class = {
      mysql: DataDuck::MysqlSource,
      postgresql: DataDuck::PostgresqlSource,
  }[db_type]

  db_source = db_class.new("source1", {
      'db_type' => db_type.to_s,
      'host' => source_host,
      'database' => source_database,
      'port' => source_port,
      'username' => source_username,
      'password' => source_password,
  })

  puts "Connecting to source database..."
  table_names = db_source.table_names
  puts "Connection successful. Detected #{ table_names.length } tables."
  puts "Creating scaffolding..."
  table_names.each do |table_name|
    DataDuck::Commands.quickstart_create_table(table_name, db_source)
  end

  config_obj = {
    'users' => {
        email => {
            'admin' => true
        }
    },
    'sources' => {
      'source1' => {
        'type' => db_type.to_s,
        'host' => source_host,
        'database' => source_database,
        'port' => source_port,
        'username' => source_username,
      }
    },
    'destinations' => {
      'destination1' => {
        'type'  => 'redshift',
        's3_bucket'  => 'YOUR_BUCKET',
        's3_region'  => 'YOUR_BUCKET_REGION',
        'host'  => 'redshift.somekeygoeshere.us-west-2.redshift.amazonaws.com',
        'port'  => 5439,
        'database'  => 'main',
        'schema'  => 'public',
        'username'  => 'YOUR_UESRNAME',
      }
    }
  }
  DataDuck::Commands.quickstart_save_file("#{ DataDuck.project_root }/config/base.yml", config_obj.to_yaml)

  DataDuck::Commands.quickstart_save_file("#{ DataDuck.project_root }/.env", """
destination1_aws_key=AWS_KEY_GOES_HERE
destination1_aws_secret=AWS_SECRET_GOES_HERE
destination1_password=REDSHIFT_PASSWORD_GOES_HERE
source1_password=#{ source_password }
""".strip)

  DataDuck::Commands.quickstart_update_gitignore

  puts "Quickstart complete!"
  puts "You still need to edit your .env and config/base.yml files with your AWS and Redshift credentials."
  puts "Run your ETL with: dataduck etl all"
  puts "For more help, visit http://dataducketl.com/docs"
end