Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
4efc7c47
Commit
4efc7c47
authored
9 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Prevent Liquibase migrations from leaving unreleased locks by running
inside a transaction.
parent
ab657241
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/java/com/metabase/corvus/migrations/LiquibaseMigrations.java
+0
-78
0 additions, 78 deletions
...a/com/metabase/corvus/migrations/LiquibaseMigrations.java
src/metabase/db.clj
+23
-6
23 additions, 6 deletions
src/metabase/db.clj
with
23 additions
and
84 deletions
src/java/com/metabase/corvus/migrations/LiquibaseMigrations.java
deleted
100644 → 0
+
0
−
78
View file @
ab657241
package
com.metabase.corvus.migrations
;
import
java.io.FileWriter
;
import
java.io.StringWriter
;
import
java.sql.SQLException
;
import
liquibase.Liquibase
;
import
liquibase.database.DatabaseFactory
;
import
liquibase.database.Database
;
import
liquibase.database.jvm.JdbcConnection
;
import
liquibase.exception.DatabaseException
;
import
liquibase.resource.ClassLoaderResourceAccessor
;
public
class
LiquibaseMigrations
{
private
static
final
String
LIQUIBASE_CHANGELOG
=
"migrations/liquibase.json"
;
public
static
final
void
setupDatabase
(
java
.
sql
.
Connection
dbConnection
)
throws
Exception
{
try
{
Database
database
=
DatabaseFactory
.
getInstance
().
findCorrectDatabaseImplementation
(
new
JdbcConnection
(
dbConnection
));
Liquibase
liquibase
=
new
Liquibase
(
LIQUIBASE_CHANGELOG
,
new
ClassLoaderResourceAccessor
(),
database
);
liquibase
.
update
(
""
);
}
catch
(
Exception
e
)
{
throw
new
DatabaseException
(
e
);
}
finally
{
if
(
dbConnection
!=
null
)
{
try
{
dbConnection
.
rollback
();
dbConnection
.
close
();
}
catch
(
SQLException
e
){
//nothing to do
}
}
}
}
public
static
final
void
teardownDatabase
(
java
.
sql
.
Connection
dbConnection
)
throws
Exception
{
try
{
Database
database
=
DatabaseFactory
.
getInstance
().
findCorrectDatabaseImplementation
(
new
JdbcConnection
(
dbConnection
));
Liquibase
liquibase
=
new
Liquibase
(
LIQUIBASE_CHANGELOG
,
new
ClassLoaderResourceAccessor
(),
database
);
liquibase
.
rollback
(
10000
,
""
);
}
catch
(
Exception
e
)
{
throw
new
DatabaseException
(
e
);
}
finally
{
if
(
dbConnection
!=
null
)
{
try
{
dbConnection
.
rollback
();
dbConnection
.
close
();
}
catch
(
SQLException
e
){
//nothing to do
}
}
}
}
public
static
final
String
genSqlDatabase
(
java
.
sql
.
Connection
dbConnection
)
throws
Exception
{
try
{
StringWriter
strw
=
new
StringWriter
();
Database
database
=
DatabaseFactory
.
getInstance
().
findCorrectDatabaseImplementation
(
new
JdbcConnection
(
dbConnection
));
Liquibase
liquibase
=
new
Liquibase
(
LIQUIBASE_CHANGELOG
,
new
ClassLoaderResourceAccessor
(),
database
);
liquibase
.
update
(
""
,
strw
);
return
strw
.
toString
();
}
catch
(
Exception
e
)
{
throw
new
DatabaseException
(
e
);
}
finally
{
if
(
dbConnection
!=
null
)
{
try
{
dbConnection
.
rollback
();
dbConnection
.
close
();
}
catch
(
SQLException
e
){
//nothing to do
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/metabase/db.clj
+
23
−
6
View file @
4efc7c47
...
...
@@ -12,7 +12,13 @@
[
metabase.db.internal
:as
i
]
[
metabase.models.interface
:as
models
]
[
metabase.util
:as
u
])
(
:import
com.metabase.corvus.migrations.LiquibaseMigrations
))
(
:import
java.io.StringWriter
java.sql.Connection
liquibase.Liquibase
(
liquibase.database
DatabaseFactory
Database
)
liquibase.database.jvm.JdbcConnection
liquibase.exception.DatabaseException
liquibase.resource.ClassLoaderResourceAccessor
))
;; ## DB FILE, JDBC/KORMA DEFINITONS
...
...
@@ -54,14 +60,25 @@
;; ## MIGRATE
(
def
^
:private
^
:const
changelog-file
"migrations/liquibase.json"
)
(
defn
migrate
"Migrate the database `:up`, `:down`, or `:print`."
[
jdbc-connection-details
direction
]
(
let
[
conn
(
jdbc/get-connection
jdbc-connection-details
)]
(
case
direction
:up
(
LiquibaseMigrations/setupDatabase
conn
)
:down
(
LiquibaseMigrations/teardownDatabase
conn
)
:print
(
LiquibaseMigrations/genSqlDatabase
conn
))))
(
try
(
jdbc/with-db-transaction
[
conn
jdbc-connection-details
]
(
let
[
^
Database
database
(
->
(
DatabaseFactory/getInstance
)
(
.findCorrectDatabaseImplementation
(
JdbcConnection.
(
jdbc/get-connection
conn
))))
^
Liquibase
liquibase
(
Liquibase.
changelog-file
(
ClassLoaderResourceAccessor.
)
database
)]
(
case
direction
:up
(
.update
liquibase
""
)
:down
(
.rollback
liquibase
10000
""
)
:print
(
let
[
writer
(
StringWriter.
)]
(
.update
liquibase
""
writer
)
(
.toString
writer
)))))
(
catch
Throwable
e
(
throw
(
DatabaseException.
e
)))))
;; ## SETUP-DB
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment