Class: Pcrd::Commands::Demo
- Inherits:
-
Thor
- Object
- Thor
- Pcrd::Commands::Demo
- Defined in:
- lib/pcrd/commands/demo.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
8 9 10 |
# File 'lib/pcrd/commands/demo.rb', line 8 def self.exit_on_failure? true end |
Instance Method Details
#reset ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pcrd/commands/demo.rb', line 101 def reset config = load_config! pool = Pcrd::Connection::Client.new(config.source) say "Dropping demo tables on #{config.source.host}/#{config.source.database}..." pool.exec_sql(Pcrd::Demo::Schema::DROP_SQL) pool.close say "Done.", :green rescue Pcrd::Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" rescue Pcrd::Config::LoadError => e raise Thor::Error, e. end |
#seed ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/pcrd/commands/demo.rb', line 75 def seed config = load_config! pool = Pcrd::Connection::Client.new(config.source) generator = Pcrd::Demo::Generator.new(pool, seed: [:seed]) say "Seeding demo database at #{config.source.host}/#{config.source.database}..." say "" counts = generator.generate(listing_count: [:rows]) pool.close say "" say "Seeding complete:", :green say " users: #{format_count(counts[:users])}" say " agents: #{format_count(counts[:agents])}" say " listings: #{format_count(counts[:listings])}" say "" say "Run `pcrd analyze` to see the column padding report." rescue Pcrd::Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" rescue Pcrd::Config::LoadError => e raise Thor::Error, e. end |
#setup ⇒ Object
28 29 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 |
# File 'lib/pcrd/commands/demo.rb', line 28 def setup config = load_config! pool = Pcrd::Connection::Client.new(config.source) say "Connecting to #{config.source.host}:#{config.source.port}/#{config.source.database}..." say "Dropping existing demo tables (if any)..." pool.exec_sql(Pcrd::Demo::Schema::DROP_SQL) say "Creating users table..." pool.exec_sql(Pcrd::Demo::Schema::USERS_DDL) say "Creating agents table..." pool.exec_sql(Pcrd::Demo::Schema::AGENTS_DDL) say "Creating listings table (with intentionally poor column ordering)..." pool.exec_sql(Pcrd::Demo::Schema::LISTINGS_DDL) pool.exec_sql(Pcrd::Demo::Schema::LISTINGS_FK_DDL) pool.close write_sample_config unless config_file_exists? say "" say "Done. Run `pcrd demo seed` to populate with sample data.", :green say "Then run `pcrd analyze` to see the column padding analysis.", :green rescue Pcrd::Connection::Error => e raise Thor::Error, "Connection failed: #{e.}" rescue Pcrd::Config::LoadError => e raise Thor::Error, e. end |