data_keeper 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/data_keeper/database_config.rb +24 -0
- data/lib/data_keeper/dumper.rb +12 -12
- data/lib/data_keeper/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1ea02e8856f7dbdcc74cd8c82a57893d792a6a2aeb5c6963258d06b8707e9a2b
         | 
| 4 | 
            +
              data.tar.gz: a6dbcdc1d8266d8a554ab6b7b1650dad9b810b5f91f8be3da1f157a877e537e9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: cb567b6fd35e1c68f051ee3b06e712dd9ed17e9895362ac7f025940b74cff0973255b51d95cd1effb91a67a7bd92188e50a30a07bc77e1f354008fbeab9f1d39
         | 
| 7 | 
            +
              data.tar.gz: eab10951b2cf77197c6d360d2676726ea01ddfc9c6696647e96806724d7cdaf370e33f046fbc2620ee1753b7ad697200e28d932ec45bb550bbd19a655f9b5f1b
         | 
| @@ -10,12 +10,26 @@ module DataKeeper | |
| 10 10 | 
             
                  env
         | 
| 11 11 | 
             
                end
         | 
| 12 12 |  | 
| 13 | 
            +
                def dumper_psql_env
         | 
| 14 | 
            +
                  env = { 'PGUSER' => server_username }
         | 
| 15 | 
            +
                  env['PGPASSWORD'] = server_password if server_password
         | 
| 16 | 
            +
                  env
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 13 19 | 
             
                def docker_env_params
         | 
| 14 20 | 
             
                  psql_env.map do |k, v|
         | 
| 15 21 | 
             
                    "-e #{k}=#{v}"
         | 
| 16 22 | 
             
                  end.join(" ")
         | 
| 17 23 | 
             
                end
         | 
| 18 24 |  | 
| 25 | 
            +
                def server_username
         | 
| 26 | 
            +
                  database_connection_config['username']
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def server_password
         | 
| 30 | 
            +
                  database_connection_config['password']
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 19 33 | 
             
                def username
         | 
| 20 34 | 
             
                  DataKeeper.docker_config[:pg_user] || database_connection_config['username']
         | 
| 21 35 | 
             
                end
         | 
| @@ -36,10 +50,20 @@ module DataKeeper | |
| 36 50 | 
             
                  DataKeeper.docker_config[:pg_port] || database_connection_config['port'] || '5432'
         | 
| 37 51 | 
             
                end
         | 
| 38 52 |  | 
| 53 | 
            +
                def server_port
         | 
| 54 | 
            +
                  database_connection_config['port'] || '5432'
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 39 57 | 
             
                def connection_args
         | 
| 40 58 | 
             
                  connection_opts = '--host=:host'
         | 
| 41 59 | 
             
                  connection_opts += ' --port=:port' if port
         | 
| 42 60 | 
             
                  connection_opts
         | 
| 43 61 | 
             
                end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                def dumper_connection_args
         | 
| 64 | 
            +
                  connection_opts = '--host=:host'
         | 
| 65 | 
            +
                  connection_opts += ' --port=:port' if server_port
         | 
| 66 | 
            +
                  connection_opts
         | 
| 67 | 
            +
                end
         | 
| 44 68 | 
             
              end
         | 
| 45 69 | 
             
            end
         | 
    
        data/lib/data_keeper/dumper.rb
    CHANGED
    
    | @@ -24,8 +24,8 @@ module DataKeeper | |
| 24 24 | 
             
                  Tempfile.create do |file|
         | 
| 25 25 | 
             
                    cmd = Terrapin::CommandLine.new(
         | 
| 26 26 | 
             
                      'pg_dump',
         | 
| 27 | 
            -
                      "#{ | 
| 28 | 
            -
                      environment:  | 
| 27 | 
            +
                      "#{dumper_connection_args} -x -Fc :database > :output_path",
         | 
| 28 | 
            +
                      environment: dumper_psql_env
         | 
| 29 29 | 
             
                    )
         | 
| 30 30 |  | 
| 31 31 | 
             
                    cmd.run(
         | 
| @@ -61,8 +61,8 @@ module DataKeeper | |
| 61 61 | 
             
                    Tempfile.create do |table_file|
         | 
| 62 62 | 
             
                      cmd = Terrapin::CommandLine.new(
         | 
| 63 63 | 
             
                        'psql',
         | 
| 64 | 
            -
                        "#{ | 
| 65 | 
            -
                        environment:  | 
| 64 | 
            +
                        "#{dumper_connection_args} -d :database -c :command > #{table_file.path}",
         | 
| 65 | 
            +
                        environment: dumper_psql_env
         | 
| 66 66 | 
             
                      )
         | 
| 67 67 |  | 
| 68 68 | 
             
                      cmd.run(
         | 
| @@ -89,8 +89,8 @@ module DataKeeper | |
| 89 89 | 
             
                    table_args = @definition.full_tables_to_export.map { |table| "-t #{table}" }.join(' ')
         | 
| 90 90 | 
             
                    cmd = Terrapin::CommandLine.new(
         | 
| 91 91 | 
             
                      'pg_dump',
         | 
| 92 | 
            -
                      "#{ | 
| 93 | 
            -
                      environment:  | 
| 92 | 
            +
                      "#{dumper_connection_args} -x -Fc :database #{table_args} > :output_path",
         | 
| 93 | 
            +
                      environment: dumper_psql_env
         | 
| 94 94 | 
             
                    )
         | 
| 95 95 |  | 
| 96 96 | 
             
                    cmd.run(
         | 
| @@ -116,8 +116,8 @@ module DataKeeper | |
| 116 116 |  | 
| 117 117 | 
             
                    cmd = Terrapin::CommandLine.new(
         | 
| 118 118 | 
             
                      'pg_dump',
         | 
| 119 | 
            -
                      "#{ | 
| 120 | 
            -
                      environment:  | 
| 119 | 
            +
                      "#{dumper_connection_args} -x --schema-only -Fc :database > :output_path",
         | 
| 120 | 
            +
                      environment: dumper_psql_env
         | 
| 121 121 | 
             
                    )
         | 
| 122 122 |  | 
| 123 123 | 
             
                    cmd.run(
         | 
| @@ -144,8 +144,8 @@ module DataKeeper | |
| 144 144 | 
             
                    sequences_args = all_sequences_to_export.map { |table| "-t #{table}" }.join(' ')
         | 
| 145 145 | 
             
                    cmd = Terrapin::CommandLine.new(
         | 
| 146 146 | 
             
                      'pg_dump',
         | 
| 147 | 
            -
                      "#{ | 
| 148 | 
            -
                      environment:  | 
| 147 | 
            +
                      "#{dumper_connection_args} -x -Fc :database #{sequences_args} > :output_path",
         | 
| 148 | 
            +
                      environment: dumper_psql_env
         | 
| 149 149 | 
             
                    )
         | 
| 150 150 |  | 
| 151 151 | 
             
                    cmd.run(database: database, host: host, port: port, output_path: sequences_dump_file.path)
         | 
| @@ -167,8 +167,8 @@ module DataKeeper | |
| 167 167 | 
             
                def all_sequences_to_export
         | 
| 168 168 | 
             
                  cmd = Terrapin::CommandLine.new(
         | 
| 169 169 | 
             
                    'psql',
         | 
| 170 | 
            -
                    "#{ | 
| 171 | 
            -
                    environment:  | 
| 170 | 
            +
                    "#{dumper_connection_args} -d :database -c :sql -A -R ',' -t",
         | 
| 171 | 
            +
                    environment: dumper_psql_env
         | 
| 172 172 | 
             
                  )
         | 
| 173 173 |  | 
| 174 174 | 
             
                  sequences = cmd.run(
         | 
    
        data/lib/data_keeper/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: data_keeper
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Roger Campos
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022-09- | 
| 11 | 
            +
            date: 2022-09-15 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         |