sqlbrite-migrations


Source link: https://github.com/lykmapipo/sqlbrite-migrations

sqlbrite-migrations

SQLBrite helper class to manage database creation and version management using an application's raw asset files.

Note!: Current all migrations must be placed on migrations folder inside assets folder

Check Sample

Installation

Add https://jitpack.io to your build.gradle with:

allprojects {

  repositories {

maven {
 url "https://jitpack.io" 
}

  
}
 
}

add sqlbite-migrations dependency into your project

dependencies {

  compile 'com.github.lykmapipo:sqlbrite-migrations:v1.0.1' 
}

Usage

import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ListView; import com.github.lykmapipo.sqlbrite.migrations.SQLBriteOpenHelper; import com.squareup.sqlbrite2.BriteDatabase; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers;  public class MainActivity extends AppCompatActivity {

private BriteDatabase database;
  private BriteAdapter adapter;
  private Disposable disposable;
  private ListView listView;

 @Override
  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

adapter = new BriteAdapter(getApplicationContext());

listView = (ListView) findViewById(R.id.list);

listView.setAdapter(adapter);

  
}

@Override
  protected void onResume() {

super.onResume();

 database = SQLBriteOpenHelper.get(getApplicationContext(), "brite", 1);

 disposable = database.createQuery("brites", "SELECT * FROM brites")

  .mapToList(Brite.MAPPER)

  .subscribeOn(Schedulers.io())

  .observeOn(AndroidSchedulers.mainThread())

  .subscribe(adapter);

}

@Override
  protected void onPause() {

super.onPause();

disposable.dispose();

  
}
 
}

Migrations

All migrations must be named after database version. So if you start a new project your first migration will be 1.yaml. When upgrading to new version the the migration file must have the name corresponding to the new database version i.e if you upgrading from version 1 to version 2 then you migration script name will be 2.yaml

All migration have the below format:

up: # sql scripts to run during database upgrade or create
- CREATE TABLE tests (name VARCHAR(45)) seeds: # sql scripts to be run during seeding
- INSERT INTO tests (name) values("Test") down: # sql scripts to run during database downgrade
- DROP TABLE tests

Where:

  • up - List of SQL DDL to be applied to a database. Mainly for creating or altering a table.
  • seeds - List of SQL DML to be applied to a database. All DML will be applied after success up DDL.
  • down - List of DML and DDL to be applied to a database when downgrading.

Whole of migration occur with a single database transaction. So up and seeding may happen or fail as whole.

Contribute

It will be nice, if you open an issue first so that we can know what is going on, then, fork this repo and push in your ideas. Do not forget to add a bit of test(s) of what value you adding.

License

(The MIT License)

Copyright (c) 2017 lykmapipo && Contributors

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.

Resources

Project to set up basics of a Java annotation processor.

Motivations

  • Provide a fluent and complete stack to write a custom annotation processor using Android Studio
  • Set up a robust testing strategy of the Processor implementation

An easy way to build RecyclerView.Adapter. This adapter also has multiple ItemViewType, if needed.

This ImageView is adjusted auto by aspect ratio.

Litho Picasso is a Litho compatible library, which provides an Image Component compatible with Picasso. Litho-Picasso supports a wide part of Picasso's functionality.

An Android library to easily implement compound buttons, radio and check boxes. It supports also a grid visualization.

By default OkHttp3 provides only in-memory implementation of CookieStore thus all the cookies won't survive for a long term changes. This is persistent cookie storage based on SharedPreferences.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes