Poirot


Source link: https://github.com/vinaysshenoy/poirot

Poirot

Automagical database migrations for GreenDao

Adding migrations in Android for databases is tricky and involves a lot a human effort. There is huge scope for human error and screwed up migrations. Poirot aims to fix that by attempting to automatically generating migrations where it can, and by forcing certain practices upon the user

Greendao Version - 2.1.0

Quick Usage

  1. Replace the GreenDao-Generator dependency in your generator project with Poirot.
  2. Define your entities using Poirot
  3. Generate your Dao classes using Poirot
  4. Use the generated PoirotDbHelper.java and your migrations will be handled automatically

Features

Poirot handles

  • Addition, deletion and renaming of tables
  • Addition of columns
  • Addition and removal of Indexes

Changing of field constraints, renaming and dropping of fields is not supported by SQLite, hence Poirot does not support it and takes steps to ensure that these actions are not allowed.

Usage

Include the dependency in your Generator project

Maven
<dependency>
  <groupId>com.vinaysshenoy</groupId>
  <artifactId>poirot</artifactId>
  <version>1.0.0</version> </dependency>
Gradle
compile 'com.vinaysshenoy:poirot:1.0.0'

Create Entities

In Poirot, instead of modifying your entity, you create a whole new set of entities for each version. This enables Poirot to examine the differences between successive schemas and generate code.

//The root package for all the generated source final Poirot poirot = new Poirot("com.poirot.example.db");
  //Used for describing change in Entity names across schemas final EntityRenameDesc.Builder entityRenameDescBuilder = new EntityRenameDesc.Builder();
  createV1Schema(poirot.create(1, false));
 createV2Schema(poirot.create(2, false));
 createV3Schema(poirot.create(3, false));
 //The current version has to be marked true createV4Schema(poirot.create(4, true, entityRenameDescBuilder

 .reset()

 .map("Function", "Department") //Function Entity from < v3 has been renamed to Department in v4

 .build()));

poirot.create() returns a standard GreenDao Schema, so you can use it as usual.

Generate your entities

After defining your entities, you generate them by calling poirot.generate().

poirot.generate("out/java/cur", "out/java/old");

The current DAO classes are generated under the "cur" directory, while the older classes are generated under the "old" directory. This allows you to test the migrations using your testing framework if you wish.

Use the generated DbHelper

Along with the entities, a PoirotDbHelper.java will be generated under out/java/cur/com/poirot/example/db/helper. All you need to do is use this class instead of GreenDao's default OpenHelper and you have automatic migrations.

final DaoMaster.OpenHelper helper = new PoirotDbHelper(application, "my_db", null);

Credits

  1. GreenDao, for an awesome ORM
  2. The core migration class structure was described in a StackOverflow [post] ( http://stackoverflow.com/questions/13373170/greendao-schema-update-and-data-migration). The core website is no longer available but the archives are present here.
  3. The amazing devs at Square for creating javapoet, without which the code generation for Poirot would've taken orders of magnitude longer

Resources

A ContactPicker library for Android, written in pure Kotlin.
Small Android library to show PDF files
A library to dynamically format your EditTexts to take currency inputs
Lightweight Android library for a new way to create toasts in Android, similar to Bootstrap alerts.
for check required text in EditText

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