Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Intellij IDEA datasource configurations when spinning a database container #635

Open
alvarosanchez opened this issue Jun 4, 2024 · 1 comment
Labels
type: improvement A minor improvement to an existing feature

Comments

@alvarosanchez
Copy link
Member

Intellij IDEA stores datasource connections locally. It would be super cool if Test Resources could have an opt-in feature to easily add them when spinning up a database container. Options that come to my mind described below.

Copy datasource settings to a build/target file, to the clipboard, or to the system output

Intellij already allows copy/pasting datasources. When you copy, what it pastes is something like this:

#DataSourceSettings#
#LocalDataSource: postgres@localhost
#BEGIN#
<data-source source="LOCAL" name="postgres@localhost" uuid="2593b01a-b2ef-470e-b90c-51237ea640c0"><database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="POSTGRES"/><driver-ref>postgresql</driver-ref><synchronize>true</synchronize><jdbc-driver>org.postgresql.Driver</jdbc-driver><jdbc-url>jdbc:postgresql://localhost:5432/postgres</jdbc-url><jdbc-additional-properties><property name="com.intellij.clouds.kubernetes.db.host.port"/><property name="com.intellij.clouds.kubernetes.db.enabled" value="false"/><property name="com.intellij.clouds.kubernetes.db.container.port"/></jdbc-additional-properties><secret-storage>master_key</secret-storage><schema-mapping/><working-dir>$ProjectFileDir$</working-dir></data-source>
#END#

We could dump this to a file, to the system out, or even copy to the clipboard so that I can paste it and start doing queries.

Add the datasource directly to .idea files.

Datasources are stored internally in these files (the files can contain multiple <data-source> tags):

<!-- .idea/dataSources.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
    <data-source source="LOCAL" name="postgres@localhost" uuid="2593b01a-b2ef-470e-b90c-51237ea640c0">
      <driver-ref>postgresql</driver-ref>
      <synchronize>true</synchronize>
      <jdbc-driver>org.postgresql.Driver</jdbc-driver>
      <jdbc-url>jdbc:postgresql://localhost:5432/postgres</jdbc-url>
      <jdbc-additional-properties>
        <property name="com.intellij.clouds.kubernetes.db.host.port" />
        <property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
        <property name="com.intellij.clouds.kubernetes.db.container.port" />
      </jdbc-additional-properties>
      <working-dir>$ProjectFileDir$</working-dir>
    </data-source>
  </component>
</project>
<!-- .idea/dataSources.local.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="dataSourceStorageLocal" created-in="IU-241.17011.79">
    <data-source name="postgres@localhost" uuid="2593b01a-b2ef-470e-b90c-51237ea640c0">
      <database-info product="" version="" jdbc-version="" driver-name="" driver-version="" dbms="POSTGRES" />
      <secret-storage>master_key</secret-storage>
      <schema-mapping />
    </data-source>
  </component>
</project>

It would be ✨magical if we could automatically add/remove these entries

@alvarosanchez alvarosanchez added the type: improvement A minor improvement to an existing feature label Jun 4, 2024
@graemerocher
Copy link
Contributor

sweet idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants