-
Notifications
You must be signed in to change notification settings - Fork 16
Generate schemas
xcesco edited this page May 2, 2018
·
1 revision
Especially when an application upgrade need to upgrade its data source schema version, it can useful to obtain schema definition generated by Kripton for a specific data-source. It can be done simply setting to true
the attribute schema
of @BindDataSource used to define SQLite database.
Given a data-source named SchoolDataSource
so defined (DAOs definition is omitted for simplicity):
public class Entity {
public long id;
public String name;
}
@BindType
public class Person extends Entity {
public String surname;
public String email;
}
@BindType
@BindTable(indexes=@BindIndex({"surname"}))
public class Professor extends Entity {
public Date birthDate;
@BindColumn(nullable=false)
public String surname;
}
@BindType
public class Seminar extends Entity {
public String location;
}
@BindDataSource(
fileName = "school",
version = 2,
daoSet = {
DaoProfessor.class, DaoSeminar.class,DaoSeminar2Student.class, DaoStudent.class },
schema=true)
public interface SchoolDataSource {
}
With schema=true
will generate in <project-root-directory>/schemas
folder a file like this:
/*
* school.schema.2.sql
* This class is generated by Kripton Annotation Processor (2.0.0)</strong></p>
*
* since Thu Aug 03 17:41:02 CEST 2017
*/
CREATE TABLE seminar (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, location TEXT);
CREATE TABLE student (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, location TEXT);
CREATE TABLE seminar_2_student (id INTEGER PRIMARY KEY AUTOINCREMENT, student_id INTEGER, seminar_id INTEGER, FOREIGN KEY(student_id) REFERENCES student(id), FOREIGN KEY(seminar_id) REFERENCES seminar(id)); CREATE UNIQUE INDEX idx_seminar_2_student_0 on seminar_2_student (student_id asc, seminar_id desc);
CREATE TABLE professor (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, birth_date TEXT, surname TEXT NOT NULL); CREATE INDEX idx_professor_0 on professor (surname);
The schema can be useful to test migration plan from a version to another.
- Introduction
- Goals & Features
- Kotlin
- Immutable or Mutable Pojo
- Annotation Processor Args
- Credits
- Articles
- Benchmarks
- Setup
- Tutorial
- Usage
- Dependencies and inspirations
- Stackoverflow
- Documentation
- SQL logging
- Data source options
- Indices
- SQL Type adapter
- Global SQL Type adapter
- Constraints
- Live data: welcome Architectural components!!
- Paged Live data
- Dynamic parts
- Transactional and batch operations
- Async Transactional and batch operations
- Global transaction
- Support for immutable POJO
- Generate Content provider
- Generate Database schema generation
- Database migration
- BindSqlColumn
- BindContentProvider
- BindContentProviderEntry
- BindContentProviderPath
- BindDao
- BindDaoMany2Many
- BindDataSource
- BindDataSourceOptions
- BindDataSourceUpdateTask
- BindIndex
- BindSqlRelation
- BindSqlAdapter
- BindSqlChildSelect
- BindSqlDelete
- BindSqlDynamicOrderBy
- BindSqlDynamicWhere
- BindSqlDynamicWhereParams
- BindSqlInsert
- BindSqlPageSize
- BindSqlParam
- BindSqlSelect
- BindSqlUpdate
- BindSqlType
- BindSqlTransaction