mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 04:58:45 +00:00
Add a log section for the database schema.
This commit is contained in:
@@ -35,6 +35,39 @@ fun SupportSQLiteDatabase.getTableRowCount(table: String): Int {
|
||||
}
|
||||
}
|
||||
|
||||
fun SupportSQLiteDatabase.getAllTables(): List<String> {
|
||||
return SqlUtil.getAllTables(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of objects that represent the table definitions in the database. Basically the table name and then the SQL that was used to create it.
|
||||
*/
|
||||
fun SupportSQLiteDatabase.getAllTableDefinitions(): List<CreateStatement> {
|
||||
return this.query("SELECT name, sql FROM sqlite_schema WHERE type = 'table' AND sql NOT NULL AND name != 'sqlite_sequence'")
|
||||
.readToList { cursor ->
|
||||
CreateStatement(
|
||||
name = cursor.requireNonNullString("name"),
|
||||
statement = cursor.requireNonNullString("sql").replace(" ", "")
|
||||
)
|
||||
}
|
||||
.filterNot { it.name.startsWith("sqlite_stat") }
|
||||
.sortedBy { it.name }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of objects that represent the index definitions in the database. Basically the index name and then the SQL that was used to create it.
|
||||
*/
|
||||
fun SupportSQLiteDatabase.getAllIndexDefinitions(): List<CreateStatement> {
|
||||
return this.query("SELECT name, sql FROM sqlite_schema WHERE type = 'index' AND sql NOT NULL")
|
||||
.readToList { cursor ->
|
||||
CreateStatement(
|
||||
name = cursor.requireNonNullString("name"),
|
||||
statement = cursor.requireNonNullString("sql")
|
||||
)
|
||||
}
|
||||
.sortedBy { it.name }
|
||||
}
|
||||
|
||||
fun SupportSQLiteDatabase.getForeignKeys(): List<ForeignKeyConstraint> {
|
||||
return SqlUtil.getAllTables(this)
|
||||
.map { table ->
|
||||
@@ -426,3 +459,8 @@ data class Index(
|
||||
val table: String,
|
||||
val columns: List<String>
|
||||
)
|
||||
|
||||
data class CreateStatement(
|
||||
val name: String,
|
||||
val statement: String
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user