pgai 0.2.0 → 0.2.2
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/README.md +6 -0
- data/lib/pgai/cli/main.rb +7 -0
- data/lib/pgai/clone_manager.rb +16 -2
- data/lib/pgai/config.rb +4 -0
- data/lib/pgai/dblab.rb +4 -0
- data/lib/pgai/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: bbd22b8be81c76ea9a661cd5b9f0befffeade51768c562bdfa9991f84e998401
         | 
| 4 | 
            +
              data.tar.gz: 9281676b174a9553b6a1042f787c8f00510f25e117c6736ce3a5f4a8bf79a0c1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a2d1852ef9c05a0827f35c1af73b3e805578cd849010dc679f2796f46eae454c468051ba4d9128e25477c5096de595f8126bc2da0540fa307351fca8eefde250
         | 
| 7 | 
            +
              data.tar.gz: e4eb38d1c0dce730db90ef99b7396e06536c193c17e41e840cd48a908f14fc684573c3d250ca8821d57086a8bc6956c5663386093a0452c61e749feede460908
         | 
    
        data/README.md
    CHANGED
    
    | @@ -63,6 +63,12 @@ pgai connect <env alias> | |
| 63 63 |  | 
| 64 64 | 
             
            Multiple `connect` commands for an environment will connect to the same clone, it won't start a new one.
         | 
| 65 65 |  | 
| 66 | 
            +
            `pgai info <env alias>` prints out a database URL variable that can be used from Rails to integrate with dblab. Example for `CI` database:
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            ```shell
         | 
| 69 | 
            +
            CI_DATABASE_URL="postgresql://foo:bar@localhost:9000/foo_test" bin/rails c -e test
         | 
| 70 | 
            +
            ```
         | 
| 71 | 
            +
             | 
| 66 72 | 
             
            ### Features
         | 
| 67 73 |  | 
| 68 74 | 
             
            - multiple psql sessions to the same clone
         | 
    
        data/lib/pgai/cli/main.rb
    CHANGED
    
    | @@ -25,6 +25,13 @@ module Pgai::Cli | |
| 25 25 | 
             
                  Pgai::CloneManager.new(env, config: configuration).cleanup
         | 
| 26 26 | 
             
                end
         | 
| 27 27 |  | 
| 28 | 
            +
                desc "reset database-name", "Reset clone's state"
         | 
| 29 | 
            +
                def reset(name)
         | 
| 30 | 
            +
                  env = configuration.enviroments.fetch(name)
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  Pgai::CloneManager.new(env, config: configuration).reset
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 28 35 | 
             
                desc "info database-name", "Show clone details"
         | 
| 29 36 | 
             
                def info(name)
         | 
| 30 37 | 
             
                  env = configuration.enviroments.fetch(name)
         | 
    
        data/lib/pgai/clone_manager.rb
    CHANGED
    
    | @@ -28,14 +28,24 @@ module Pgai | |
| 28 28 | 
             
                  port_forward.stop
         | 
| 29 29 | 
             
                end
         | 
| 30 30 |  | 
| 31 | 
            +
                def reset
         | 
| 32 | 
            +
                  configure_enviroment
         | 
| 33 | 
            +
                  return unless find_raw_clone
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  dblab.reset_clone(id: clone_id)
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 31 38 | 
             
                def info
         | 
| 32 39 | 
             
                  configure_enviroment
         | 
| 33 40 |  | 
| 34 41 | 
             
                  clone = find_clone
         | 
| 35 42 | 
             
                  return {} unless clone
         | 
| 36 43 |  | 
| 44 | 
            +
                  database_url = "#{enviroment_alias.to_s.upcase}_DATABASE_URL='#{clone.database_url}'"
         | 
| 45 | 
            +
             | 
| 37 46 | 
             
                  {
         | 
| 38 | 
            -
                     | 
| 47 | 
            +
                    psql_connection_string: clone.connection_string,
         | 
| 48 | 
            +
                    rails_database_url: database_url,
         | 
| 39 49 | 
             
                    created_at: clone.created_at,
         | 
| 40 50 | 
             
                    data_state_at: clone.data_state_at
         | 
| 41 51 | 
             
                  }
         | 
| @@ -108,8 +118,12 @@ module Pgai | |
| 108 118 | 
             
                  environment.fetch(:port)
         | 
| 109 119 | 
             
                end
         | 
| 110 120 |  | 
| 121 | 
            +
                def enviroment_alias
         | 
| 122 | 
            +
                  environment.fetch(:alias)
         | 
| 123 | 
            +
                end
         | 
| 124 | 
            +
             | 
| 111 125 | 
             
                def clone_id
         | 
| 112 | 
            -
                  @clone_id ||= [config.clone_prefix,  | 
| 126 | 
            +
                  @clone_id ||= [config.clone_prefix, enviroment_alias].join("_")
         | 
| 113 127 | 
             
                end
         | 
| 114 128 |  | 
| 115 129 | 
             
                def clone_user
         | 
    
        data/lib/pgai/config.rb
    CHANGED
    
    | @@ -10,6 +10,10 @@ module Pgai | |
| 10 10 | 
             
                  def connection_string
         | 
| 11 11 | 
             
                    "'host=#{host} port=#{port} user=#{user} dbname=#{dbname} password=#{password}'"
         | 
| 12 12 | 
             
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def database_url
         | 
| 15 | 
            +
                    "postgresql://#{user}:#{password}@#{host}:#{port}/#{dbname}"
         | 
| 16 | 
            +
                  end
         | 
| 13 17 | 
             
                end
         | 
| 14 18 |  | 
| 15 19 | 
             
                attr_accessor :clone_prefix
         | 
    
        data/lib/pgai/dblab.rb
    CHANGED
    
    
    
        data/lib/pgai/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: pgai
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Marius Bobin
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023-05- | 
| 11 | 
            +
            date: 2023-05-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: thor
         |