Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/g4s8/android-migrator
Apply SQLite migrations to your Android database!
https://github.com/g4s8/android-migrator
android android-library android-migrator assets library migration migrator sqlite
Last synced: 2 days ago
JSON representation
Apply SQLite migrations to your Android database!
- Host: GitHub
- URL: https://github.com/g4s8/android-migrator
- Owner: g4s8
- License: mit
- Created: 2017-01-02T12:26:23.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-21T09:16:23.000Z (over 7 years ago)
- Last Synced: 2023-02-27T18:12:12.194Z (over 1 year ago)
- Topics: android, android-library, android-migrator, assets, library, migration, migrator, sqlite
- Language: Java
- Homepage:
- Size: 122 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Android-Migrator
Android migrator will help you to apply migrations from assets files via default database framework (`SQLiteOpenHelper`).[![Build Status](https://img.shields.io/travis/g4s8/Android-Migrator.svg?style=flat-square)](https://travis-ci.org/g4s8/Android-Migrator)
[![License](https://img.shields.io/github/license/g4s8/Android-Migrator.svg?style=flat-square)](https://github.com/g4s8/Android-Migrator/blob/master/LICENSE)
[![Test Coverage](https://img.shields.io/codecov/c/github/g4s8/Android-Migrator.svg?style=flat-square)](https://codecov.io/github/g4s8/Android-Migrator?branch=master)
[![Bintray](https://img.shields.io/bintray/v/g4s8/maven-android/com.g4s8.amigrator.svg?style=flat-square)](https://bintray.com/g4s8/maven-android/com.g4s8.amigrator/_latestVersion)## Setup
Add gradle dependency
```gradle
dependencies {
compile 'com.g4s8:amigrator:'
}
```
[see latest release](https://github.com/g4s8/Android-Migrator/releases/latest)Add migration files to assets folder "migrations" (folder name can be customized).
Each migration file should be named with format: `.sql`, where visersion is integer number.
```
assets
migrations
1.sql
2.sql
3.sql
```Migration files should be filled with sqlite statements, ended with semicolon: ';'. Migrator ignores empty lines and spaces.
Comments ('--') are not supported yet.
```sql
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT
);INSERT INTO users (name) VALUES ('Jimmy');
```Apply migrations in you android sqlite-helper.
```java
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;public final class Sqlite extends SQLiteOpenHelper {
private final SQLiteMigrations migrations;
private final int version;
public Sqlite(final Context ctx, final int version) {
super(context, "db_name", null, version);
migrations = new SQLiteMigrations(ctx); // or provide custom assets folder as second parameter
this.version = version;
}
@Override
public void onCreate(final SQLiteDatabase db) {
migrations.apply(db, 0, version);
}
@Override
public void onUpgrade(
final SQLiteDatabase db,
final int oldVersion,
final int newVersion
) {
migrations.apply(db, oldVersion, newVersion);
}
}
```