Last active
January 26, 2022 21:00
-
-
Save ericdagenais/69265926b3304314dbbc9f60a76032ba to your computer and use it in GitHub Desktop.
Windows: Import PgAdmin 3 Connections to Navicat and DataGrip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'win32/registry' | |
passwords = Hash.new | |
file = nil | |
begin | |
file = File.new("#{ENV['APPDATA']}\\postgresql\\pgpass.conf", "r") | |
while (line = file.gets) | |
c = line.split(':') | |
key = "#{c[0]}:#{c[1]}:#{c[2]}:#{c[3]}" | |
passwords[key] = c[4].strip if c.length > 4 | |
end | |
rescue => err | |
puts "Exception: #{err}" | |
ensure | |
file.close | |
end | |
a = nil | |
begin | |
File.open('ide-scripting.js', 'w') { | |
|file| | |
file.write("var psiManager = com.intellij.util.containers.ContainerUtil.findInstance(com.intellij.database.psi.DbPsiFacade.getInstance(IDE.project).getDbManagers(), com.intellij.database.psi.DefaultDbPsiManager.class);\n"); | |
Win32::Registry::HKEY_CURRENT_USER.open("Software\\pgAdmin III\\Servers") do |reg| | |
reg.each_key { | |
|n, v| | |
reg.open(n) do |sub| | |
description = sub['Description'].tr(" ", "_") | |
server = sub['Server'] | |
port = sub['Port'] | |
username = sub['Username'] | |
key = "#{server}:#{port}:*:#{username}" | |
password = "#{passwords[key]}" | |
file.write("psiManager.addDataSource(new com.intellij.database.dataSource.LocalDataSource(\"#{description}\", \"org.postgresql.Driver\", \"jdbc:postgresql://#{server}:5432/postgres\", \"#{username}\", \"#{password}\"));\n") | |
end | |
} | |
end | |
} | |
puts "Export complete" | |
puts "Please use Datagrip to run the ide script located in #{File.absolute_path("./ide-scripting.js")}" | |
rescue => err | |
puts "Exception: #{err}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment