Skip to content

Commit 16a86b2

Browse files
committed
[Database] Added export schema for database
1 parent f5c2377 commit 16a86b2

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

app/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ android {
5858
versionName "v${versionMayor}.${versionMinor}.${versionPatch} ${versionBuild}"
5959

6060
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
61+
62+
javaCompileOptions {
63+
annotationProcessorOptions {
64+
compilerArgumentProviders(
65+
new RoomSchemaArgProvider(new File(projectDir, "schemas"))
66+
)
67+
}
68+
}
6169
}
6270

6371
buildTypes {
@@ -133,4 +141,23 @@ dependencies {
133141

134142
implementation "org.slf4j:slf4j-simple:1.7.9"
135143
implementation 'org.kohsuke:github-api:1.314'
144+
}
145+
146+
class RoomSchemaArgProvider implements CommandLineArgumentProvider {
147+
148+
@InputDirectory
149+
@PathSensitive(PathSensitivity.RELATIVE)
150+
File schemaDir
151+
152+
RoomSchemaArgProvider(File schemaDir) {
153+
this.schemaDir = schemaDir
154+
schemaDir.mkdirs()
155+
}
156+
157+
@Override
158+
Iterable<String> asArguments() {
159+
// Note: If you're using KSP, change the line below to return
160+
// ["room.schemaLocation=${schemaDir.path}"].
161+
return ["-Aroom.schemaLocation=${schemaDir.path}"]
162+
}
136163
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 1,
5+
"identityHash": "6fb485e6e64b1e9cc5ceeb0440c58e23",
6+
"entities": [
7+
{
8+
"tableName": "SecureElement",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`data` BLOB, `title` TEXT, `type` INTEGER NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
10+
"fields": [
11+
{
12+
"fieldPath": "detail",
13+
"columnName": "data",
14+
"affinity": "BLOB",
15+
"notNull": false
16+
},
17+
{
18+
"fieldPath": "title",
19+
"columnName": "title",
20+
"affinity": "TEXT",
21+
"notNull": false
22+
},
23+
{
24+
"fieldPath": "type",
25+
"columnName": "type",
26+
"affinity": "INTEGER",
27+
"notNull": true
28+
},
29+
{
30+
"fieldPath": "id",
31+
"columnName": "id",
32+
"affinity": "INTEGER",
33+
"notNull": true
34+
}
35+
],
36+
"primaryKey": {
37+
"autoGenerate": true,
38+
"columnNames": [
39+
"id"
40+
]
41+
},
42+
"indices": [],
43+
"foreignKeys": []
44+
},
45+
{
46+
"tableName": "MasterPassword",
47+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `hash` BLOB)",
48+
"fields": [
49+
{
50+
"fieldPath": "id",
51+
"columnName": "id",
52+
"affinity": "INTEGER",
53+
"notNull": true
54+
},
55+
{
56+
"fieldPath": "hash",
57+
"columnName": "hash",
58+
"affinity": "BLOB",
59+
"notNull": false
60+
}
61+
],
62+
"primaryKey": {
63+
"autoGenerate": true,
64+
"columnNames": [
65+
"id"
66+
]
67+
},
68+
"indices": [],
69+
"foreignKeys": []
70+
}
71+
],
72+
"views": [],
73+
"setupQueries": [
74+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
75+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6fb485e6e64b1e9cc5ceeb0440c58e23')"
76+
]
77+
}
78+
}

app/src/main/java/de/davis/passwordmanager/database/SecureElementDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import de.davis.passwordmanager.security.element.SecureElement;
1515

1616
@TypeConverters({Converters.class})
17-
@Database(version = 1, entities = {SecureElement.class, MasterPassword.class}, exportSchema = false)
17+
@Database(version = 1, entities = {SecureElement.class, MasterPassword.class})
1818
public abstract class SecureElementDatabase extends RoomDatabase {
1919

2020
public static final String DB_NAME = "secure_element_database";

0 commit comments

Comments
 (0)