|
1 | 1 | Automatic Schema Updating
|
2 | 2 | ========
|
3 |
| -GitBucket uses H2 database to manage project and account data. GitBucket updates database schema automatically in the first run after the upgrading. |
| 3 | +GitBucket updates database schema automatically using [Solidbase](https://github.com/gitbucket/solidbase) in the first run after the upgrading. |
4 | 4 |
|
5 |
| -To release a new version of GitBucket, add the version definition to the [gitbucket.core.servlet.AutoUpdate](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/servlet/AutoUpdate.scala) at first. |
| 5 | +To release a new version of GitBucket, add the version definition to the [gitbucket.core.GitBucketCoreModule](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/GitBucketCoreModule.scala) at first. |
6 | 6 |
|
7 | 7 | ```scala
|
8 |
| -object AutoUpdate { |
9 |
| - ... |
10 |
| - /** |
11 |
| - * The history of versions. A head of this sequence is the current GitBucket version. |
12 |
| - */ |
13 |
| - val versions = Seq( |
14 |
| - Version(1, 0) |
| 8 | +object GitBucketCoreModule extends Module("gitbucket-core", |
| 9 | + new Version("4.0.0", |
| 10 | + new LiquibaseMigration("update/gitbucket-core_4.0.xml"), |
| 11 | + new SqlMigration("update/gitbucket-core_4.0.sql") |
| 12 | + ), |
| 13 | + new Version("4.1.0"), |
| 14 | + new Version("4.2.0", |
| 15 | + new LiquibaseMigration("update/gitbucket-core_4.2.xml") |
15 | 16 | )
|
16 |
| - ... |
| 17 | +) |
| 18 | +``` |
| 19 | + |
| 20 | +Next, add a XML file which updates database schema into [/src/main/resources/update/](https://github.com/gitbucket/gitbucket/tree/master/src/main/resources/update) with a filenane defined in `GitBucketCoreModule`. |
| 21 | + |
| 22 | +```xml |
| 23 | +<?xml version="1.0" encoding="UTF-8"?> |
| 24 | +<changeSet> |
| 25 | + <addColumn tableName="REPOSITORY"> |
| 26 | + <column name="ENABLE_WIKI" type="boolean" nullable="false" defaultValueBoolean="true"/> |
| 27 | + <column name="ENABLE_ISSUES" type="boolean" nullable="false" defaultValueBoolean="true"/> |
| 28 | + <column name="EXTERNAL_WIKI_URL" type="varchar(200)" nullable="true"/> |
| 29 | + <column name="EXTERNAL_ISSUES_URL" type="varchar(200)" nullable="true"/> |
| 30 | + </addColumn> |
| 31 | +</changeSet> |
17 | 32 | ```
|
18 | 33 |
|
19 |
| -Next, add a SQL file which updates database schema into [/src/main/resources/update/](https://github.com/gitbucket/gitbucket/tree/master/src/main/resources/update) as ```MAJOR_MINOR.sql```. |
| 34 | +Solidbase stores the current version to `VERSIONS` table and checks it at start-up. If the stored version differs from the actual version, it executes differences between the stored version and the actual version. |
| 35 | + |
| 36 | +We can add the SQL file instead of the XML file using `SqlMigration`. It try to load a SQL file from classpath as following order: |
20 | 37 |
|
21 |
| -GitBucket stores the current version to ```GITBUCKET_HOME/version``` and checks it at start-up. If the stored version differs from the actual version, it executes differences of SQL files between the stored version and the actual version. And ```GITBUCKET_HOME/version``` is updated by the actual version. |
| 38 | +1. Specified path (if specified) |
| 39 | +2. `${moduleId}_${version}_${database}.sql` |
| 40 | +3. `${moduleId}_${version}.sql` |
22 | 41 |
|
23 |
| -We can also add any Scala code for upgrade GitBucket which modifies resources other than database. Override ```Version.update``` like below: |
| 42 | +Also we can add any code by extending `Migration`: |
24 | 43 |
|
25 | 44 | ```scala
|
26 |
| -val versions = Seq( |
27 |
| - new Version(1, 3){ |
28 |
| - override def update(conn: Connection): Unit = { |
29 |
| - super.update(conn) |
30 |
| - // Add any code here! |
| 45 | +object GitBucketCoreModule extends Module("gitbucket-core", |
| 46 | + new Version("4.0.0", new Migration(){ |
| 47 | + override def migrate(moduleId: String, version: String, context: java.util.Map[String, String]): Unit = { |
| 48 | + ... |
31 | 49 | }
|
32 |
| - }, |
33 |
| - Version(1, 2), |
34 |
| - Version(1, 1), |
35 |
| - Version(1, 0) |
| 50 | + }) |
36 | 51 | )
|
37 | 52 | ```
|
| 53 | + |
| 54 | +See more details [README of Solidbase](https://github.com/gitbucket/solidbase). |
0 commit comments