Is it possible to keep a Postgres database schema under source control using DataGrip? - postgresql

With Microsoft SQL Server, there is a great schema comparison tool which lets you keep a database schema under source control and push changes in both directions (schema project to database and database to schema project) which can then be kept under source control. This made development very easy directly on the local database, push the changes to the source controlled project and then apply the changes to other environments when required by using the schema comparison tool to generate the updates from the diff.
Is there any way to do something similar to this with DataGrip for PostgreSQL?
Including how to keep a database as schema files.
I've seen that there is VCS integration but I can't get it to generate a project from a database and Google doesn't seem to help.
Any help would be greatly appreciated.
Thanks, James

There is no full integration for now. This is the ticket to follow: https://youtrack.jetbrains.com/issue/DBE-3852
But you can now already generate you file-project for your database.
Select schema in the database explorer
Context menu -> SQL scripts -> SQL Generator
Choose the tab with the diskette, select options
Press Save.

Related

Is there any way to run Flyway task excluding some tables?

I'm currently using Flyway to manage migrations on an application which uses Postgis (PostgreSQL geospatial extension).
This plugin uses a table called spatial_ref_sys which is located in the same schema the application uses too, when I call mvn flyway:clean I'm getting an error indicating that Flyway was unable to delete this table (it was created using user postgres); if I change the owner to my application database user, then the error changes to:
ERROR: cannot drop table spatial_ref_sys because extension postgis requires it
[ERROR] Hint: You can drop extension postgis instead.
However, I don't want to drop these items, which are external to my application logic, as they are just "auxiliars".
I have seen two questions where Axel Fontaine said the feature of ignore some table(s) is not supported (both questions are two or more years old), I even have cloned the GitHub repo to add this feature to Flyway by myself, and I've been reading some parts of the code where this change could be implemented; but I'm suspecting it will affect several parts of the code, and my unknowledgement about it could make the things harder..
So, I'm looking some help to implement the change, or maybe some ideas to do a work-around this issue..
I'm thinking in simply do DROP of the entire database and recreate it, then recreate the geospatial extensions (Postgis, PGRouting, etc), and make the migration using Flyway, but this will be not much suitable if I have to do it several times during the development process..
I had this problem for test environment and i wanted to delete schema by flyway. I fixed it by manipulating flyway spring bean sequence. First, I dropped postgis extension before flyway.clean() and then at the first line of V1__init.sql add CREATE EXTENSION postgis SCHEMA public;:
#Bean
#Profile("test")
public Flyway flyway(DataSource dataSource) {
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setLocations("classpath:db/migration");
runSql("drop extension IF EXISTS postgis CASCADE;", dataSource);
flyway.clean();
flyway.migrate();
return flyway;
}

DBeaver Can't access non-default database

I'm using DBeaver 3.8.0 and trying to setup general connection to my local PostgreSQL database.
To view all the databases i have, I check the "Show non-default databases" checkbox. And when I try to access Schemas of one of my databases - I'm getting the error
org.jkiss.dbeaver.DBException: Can't access non-default database
Try to set your database active which you choose to open the schema:
Right-click on the Db Connection in the database navigator (right-click on PostgreSQL)
Click on edit connection
Select PostgreSQL tab
Select Show all databases
Click ok to save
Note: I am using DBeaver Enterprise 7.0.0
For more recent versions of DBeaver, you can improve this confusing default behavior.
You need to change an "Editors" setting. There are several ways to get to the setting, an easy way is:
[Postgres - #name#] right-click > Properties
Under Editors, check the auto-sync box:
After that, any time you click on a database in the right-hand navigator, it will automatically be set as the active database, so things should just work.
These types of pain points are enough to drive you away from new tools, this one in particular. Hang in there!

typo3 4.7 recreate database

Is it possible to recreate the database from scratch on a typo3 4.7.10?
After a migration the database got lost and only the files are available. My job now is to create a new database for it.
Do I have to install a typo3 4.7 and then use this database or is it somehow possible to recreate the database with the current installation?
You can create an empty db via phpMyAdmin, for example.
Then go to Install Tool -> Basic Configuration and enter your db credentials there. After that you can switch to DB analyzer and click on "Compare" button.
TYPO3 will then prompt all the SQL queries it will perform, which in your case will be "CREATE TABLE ...". Just agree with that and your empty TYPO3 db will be created.

How to Manage EF Migrations Between Development and Production Databases?

Before anyone marks this as a duplicate, none of the questions similar to this addressed any of my concerns or answered any of my questions.
I am currently developing all the POCOs and data contexts in a library project, and running migrations from within this project. The database I'm updating is the development database.
What do I do if I want to create the current schema to a fresh, new database? I figure that all I have to do is to change the connection string in web.config and run Update-Database, correct?
While the live/production database is up and running, I want to add new columns and new tables to the schema, and test it out in development. So I switch back the connection string to the development database's connection string, and run Update-Database.
Going back and forth between two databases seems like I'll get conflicts between _MigrationHistory tables and the auto-generated migration scripts.
Is it safe to manually delete the _MigrationHistory tables in both databases, and/or delete the migration files in /Migrations (so I'll run Add-Migration again)? How do we manage this?
What do I do if I want to create the current schema to a fresh, new database?
- Yes, to create fresh database to the current migration level you simply modify the connection string to point to a database that does not yet exist and run update-database. It will run all the migrations in order.
As far as migrating to the Production database, I am running the update-database command with the -script switch to acquire the raw sql and then applying that script to the production database manually. This is helpful if you need to keep a record of sql commands run against the database as well. Additionally, you can generate the script explicitly from a specific migration to another specific migration via some of the other update-database switches.
Alternatively, you can create an Idempotent script that works from any migration by using the–SourceMigration $InitialDatabase switch and optionally specify an end migration with –TargetMigration
If you delete the _MigrationHistory tables you will have issues where the generated script will be trying to add columns that already exist and such.
You may find the following link helpful:
Microsoft Entity Framework Migrations
I would suggest having a separate trunk in your source code repository - one pointing to production and one to development to avoid risks of switching between the two in visual studio.
Me also had the same problem, even when using one and the same database - due to some merges in the repository, and the mix of automatic/manual migrations. For some reason the EF was not taking into account the target database, and calculating what scripts need to me executed, based on what is already in the database.
To fix this, I go to the [__MigrationHistory] table on the target database and get the latest migration name. This will help EF to determinate the state of the DB, and will execute just the scripts needed.
then the following script is run:
update-database -script -sourcemigration {latest migration name}
This creates update script that is specific to the target database (the connection string should be correct, as discussed in the other comments)
you can also use -force parameter if needed
this way you can update any database to latest version, no mater in what version you found it, if it has MigrationHistory table.
Hope this helps
My production and my developmental database went out of synch and it gave me endless problems. I solved it using a tool from Red-Gate to match up the databases. After using the tool, the databases were exactly the same but my migration was not working and I started to get odd errors i.e. trying to add tables/ columns that already existed etc. I solved that. I just deleted the migration folder on the local, recreated it, added the initial migration, updated the database and then matched the data of this migration file (local) to the one on the host (delete all the data in the migration file on the host, and add the same data that is on the local into the host). A more detailed explanation is at:
migration synch developmental and production databases

Mysql workbench refresh EER Diagram from server

is it possible to refetch or reimport a whole database structure from a server in mysql workbench?
I've tried the synchronize options (both Model and any source), but it always works the other way round (workbench->server) and drops new columns which i've created online / outside of mysql workbench..
i'm using the latest version 5.2.41.
Thanks for any help
Use the latest version 5.2.42 and do a "Database > Synchronize with Any Source" because it appears that you are still experiencing this bug
http://bugs.mysql.com/bug.php?id=61211
At the step "Select changes to Apply", default it "Update source" (you see the arrow from Left->Right). In your case, you should select the tables and click "Update Model", it will sync from Mysql to Model.