/
index.html
151 lines (123 loc) · 6.38 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
layout: api
pill: overview
subtitle: API
---
<div id="api">
<h1>API</h1>
<p>Flyway brings the largest benefits when <strong>integrated within an application</strong>. By integrating Flyway
you can ensure that the application and its <strong>database will always be compatible</strong>, with no manual
intervention required. Flyway checks the version of the database and applies new migrations automatically
<strong>before</strong> the rest of the application starts. This is important, because the database must first
be migrated to a state the rest of the code can work with. </p>
<h2>Download</h2>
<h3>Direct</h3>
<table class="table">
<thead>
<tr>
<th><strong>Binary</strong></th>
<th><strong>Source</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="http://repo1.maven.org/maven2/org/flywaydb/flyway-core/{{site.flywayVersion}}/flyway-core-{{site.flywayVersion}}.jar">flyway-core-{{site.flywayVersion}}.jar</a>
</td>
<td>
<a href="http://repo1.maven.org/maven2/org/flywaydb/flyway-core/{{site.flywayVersion}}/flyway-core-{{site.flywayVersion}}-sources.jar">flyway-core-{{site.flywayVersion}}-sources.jar</a>
</td>
</tr>
</table>
<h3>Build Tools</h3>
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active marketing-item"><a href="#tab-maven" data-toggle="tab"><i class="fa fa-maxcdn"></i> Maven</a>
</li>
<li class="marketing-item"><a href="#tab-gradle" data-toggle="tab"><i class="fa fa-cogs"></i> Gradle</a>
</li>
<li class="marketing-item"><a href="#tab-ant" data-toggle="tab"><i class="fa fa-wrench"></i> Ant + Ivy</a>
</li>
<li class="marketing-item"><a href="#tab-sbt" data-toggle="tab"><i class="fa fa-angle-right"></i> SBT</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab-maven">
<pre class="prettyprint"><dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>{{ site.flywayVersion }}</version>
</dependency></pre>
</div>
<div class="tab-pane" id="tab-gradle">
<pre class="prettyprint">compile "org.flywaydb:flyway-core:{{ site.flywayVersion }}"</pre>
</div>
<div class="tab-pane" id="tab-ant">
<pre class="prettyprint"><dependency org="org.flywaydb" name="flyway-core" rev="{{ site.flywayVersion }}"/></pre>
</div>
<div class="tab-pane" id="tab-sbt">
<pre class="prettyprint">"org.flywaydb" % "flyway-core" % "{{ site.flywayVersion }}"</pre>
</div>
</div>
</div>
<h2>The Flyway Class</h2>
<p>The central piece of Flyway's database migration infrastructure is the <strong><a
href="/documentation/api/javadoc/org/flywaydb/core/Flyway">org.flywaydb.core.Flyway</a></strong>
class. It is your <strong>one-stop shop</strong> for working with Flyway programmatically. It serves both as a
<strong>configuration</strong> and a <strong>launching</strong> point for all of Flyway's functions. </p>
<h2>Programmatic Configuration (Java)</h2>
<p>Flyway is super easy to use programmatically: </p><pre class="prettyprint">import org.flywaydb.core.Flyway;
...
Flyway flyway = new Flyway();
flyway.setDataSource(...);
flyway.migrate();
// Start the rest of the application (incl. Hibernate)
...</pre>
<div class="well"><strong>Tip:</strong> When running inside a <a href="https://boxfuse.com">Boxfuse</a>
instance (both locally and on AWS), Flyway will automatically use the JDBC url, user and password
<a href="https://boxfuse.com/docs/databases#envvars">provided by Boxfuse</a>.</div>
<h2>Programmatic Configuration (Android)</h2>
<p>In order to use Flyway on Android you have to add flyway-core as well as SQLDroid as dependencies. There are two things to keep in mind with Android: First, you have to load the migrations as <i>assets</i>, not <i>resources</i> and second, you have to let Flyway know your Android context, by calling <code>ContextHolder.setContext</code>.</p>
<p>1. Add the necessary dependencies to <code>build.gradle</code>:</p>
<pre class="prettyprint">dependencies {
// Your other dependencies
// ...
compile 'org.flywaydb:flyway-core:{{ site.flywayVersion }}'
compile 'org.sqldroid:sqldroid:1.0.3'
}</pre>
<p>2. Make source that your migrations are included as assets (notice that assets have to be declared in the project itself and not in a dependency. But you can use reference e.g. <code>'../lib/src/main/resources'</code> to use the resources of a lib project)</p>
<pre class="prettyprint">android {
// SDK, config, buildTypes, etc
// ...
sourceSets {
// Place your db/migration folder here
main { assets.srcDirs = ['src/main/assets'] }
}
// ...
}</pre>
<p>3. Include the setup in your main activity onCreate or application onCreate:</p>
<pre class="prettyprint">import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.android.ContextHolder;
import org.sqldroid.DroidDataSource;
...
DroidDataSource dataSource = new DroidDataSource(getPackageName(), "...");
ContextHolder.setContext(this);
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.migrate();</pre>
<h2 id="spring">Spring Configuration</h2>
<p>As an alternative to the programmatic configuration, here is how you can configure and start Flyway in a typical
Spring application: </p>
<pre class="prettyprint"><bean id="flyway" class="org.flywaydb.core.Flyway" init-method="migrate">
<property name="dataSource" ref="..."/>
...
</bean>
<!-- The rest of the application (incl. Hibernate) -->
<!-- Must be run after Flyway to ensure the database is compatible with the code -->
<bean id="sessionFactory" class="..." depends-on="flyway">
...
</bean></pre>
<p class="next-steps">
<a class="btn btn-primary" href="/documentation/api/hooks">API: Hooks <i class="fa fa-arrow-right"></i></a>
</p>
</div>