A scuffed utility library for jetbrains Exposed to support migrations
This library is a super-basic migration tool for the Kotlin SQL Framework Exposed by Jetbrains.
See this issue for more information.
Currently, only migrations to a higher version are possible, downgrades are not supported.
You can include Exposed Migrations in your project by adding the following:
<dependency>
<groupId>gay.solonovamax</groupId>
<artifactId>exposed-migrations</artifactId>
<version>4.0.0</version>
</dependency>
implementation 'gay.solonovamax:exposed-migrations:4.0.0'
implementation("gay.solonovamax:exposed-migrations:4.0.0")
Put all your migrations in the same package, for
example com.your.program.migration
.
Create a class named MXXXX
like bellow, XXXX
being the number of this
migration class.
Note: you can append anything to MXXXX
for extra context,
i.e. M0001_FirstMigration
package com.your.program.migration
class M0001 : Migration() {
/** a static snapshot of [SomeTable] */
private class SomeTable : IntIdTable() {
init {
integer("someField")
index(true, someField)
}
}
override fun run() {
SchemaUtils.create(SomeTestTable)
}
}
and
val migrations = loadMigrationsFrom("com.your.program.migration")
runMigrations(migrations)
or list your migrations manually
runMigrations(listOf(M0001()))
The line above will find all classes named according to the
regex ^M(\\d+)_(.*)$
and apply them in order of the number after M
.
A table named MIGRATIONS
is used to store all executed migrations. It is used
to find the current state of the database and to determine which migrations
still need to be executed.
This is a fork of Suwayomi/exposed-migrations which is in turn a fork of the original exposed-migrations by Andreas Mausch.
This software is licensed under MIT
.
MIT License
Copyright (c) 2021 solonovamax
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.