Commit db913367 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

DnsRule now contains the source it was imported from (if it isn't a user-defined rule)

parent f840d78f
......@@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 6,
"identityHash": "207633d815093431015a9df18f6521b0",
"identityHash": "be58818eae851a6b386c96630cd3b3c2",
"entities": [
{
"tableName": "CachedResponse",
......@@ -101,7 +101,7 @@
},
{
"tableName": "DnsRule",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` INTEGER NOT NULL, `host` TEXT NOT NULL, `ttl` INTEGER NOT NULL, `record` TEXT NOT NULL)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` INTEGER NOT NULL, `host` TEXT NOT NULL, `ttl` INTEGER NOT NULL, `record` TEXT NOT NULL, `importedFrom` INTEGER, FOREIGN KEY(`importedFrom`) REFERENCES `HostSource`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
......@@ -132,6 +132,12 @@
"columnName": "record",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "importedFrom",
"columnName": "importedFrom",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
......@@ -140,12 +146,50 @@
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
"indices": [
{
"name": "index_DnsRule_importedFrom",
"unique": false,
"columnNames": [
"importedFrom"
],
"createSql": "CREATE INDEX `index_DnsRule_importedFrom` ON `${TABLE_NAME}` (`importedFrom`)"
},
{
"name": "index_DnsRule_host",
"unique": false,
"columnNames": [
"host"
],
"createSql": "CREATE INDEX `index_DnsRule_host` ON `${TABLE_NAME}` (`host`)"
},
{
"name": "index_DnsRule_host_type",
"unique": false,
"columnNames": [
"host",
"type"
],
"createSql": "CREATE INDEX `index_DnsRule_host_type` ON `${TABLE_NAME}` (`host`, `type`)"
}
],
"foreignKeys": [
{
"table": "HostSource",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"importedFrom"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "HostSource",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `source` TEXT NOT NULL, `enabled` INTEGER NOT NULL)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `enabled` INTEGER NOT NULL, `name` TEXT NOT NULL, `source` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
......@@ -153,6 +197,12 @@
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "enabled",
"columnName": "enabled",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
......@@ -164,12 +214,6 @@
"columnName": "source",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "enabled",
"columnName": "enabled",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
......@@ -185,7 +229,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '207633d815093431015a9df18f6521b0')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'be58818eae851a6b386c96630cd3b3c2')"
]
}
}
\ No newline at end of file
......@@ -51,7 +51,7 @@ private val MIGRATION_4_5 = migration(4, 5) {
}
private val MIGRATION_5_6 = migration(5, 6) {
Logger.logIfOpen("DB_MIGRATION", "Migrating from 5 to 6")
it.execSQL("CREATE TABLE IF NOT EXISTS `DnsRule` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` INTEGER NOT NULL, `host` TEXT NOT NULL, `ttl` INTEGER NOT NULL, `record` TEXT NOT NULL)")
it.execSQL("CREATE TABLE IF NOT EXISTS `DnsRule` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` INTEGER NOT NULL, `host` TEXT NOT NULL, `ttl` INTEGER NOT NULL, `record` TEXT NOT NULL, `importedFrom` INTEGER, FOREIGN KEY(`importedFrom`) REFERENCES `HostSource`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )")
it.execSQL("CREATE TABLE IF NOT EXISTS `HostSource` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `source` TEXT NOT NULL, `enabled` INTEGER NOT NULL)")
Logger.logIfOpen("DB_MIGRATION", "Migration from 5 to 6 completed")
}
......
......@@ -26,4 +26,7 @@ interface DnsRuleDao {
@Query("DELETE FROM DnsRule")
fun deleteAll()
@Query("DELETE FROM DnsRule WHERE importedFrom IS NULL")
fun deleteAllExceptUserRules()
}
\ No newline at end of file
package com.frostnerd.smokescreen.database.entities
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import androidx.room.*
import com.frostnerd.smokescreen.database.converters.DnsTypeConverter
import com.frostnerd.smokescreen.database.converters.StringListConverter
import org.minidns.record.Record
/*
......@@ -25,12 +22,23 @@ import org.minidns.record.Record
*
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
@Entity(tableName = "DnsRule")
@Entity(
tableName = "DnsRule",
foreignKeys = [ForeignKey(
entity = HostSource::class,
parentColumns = arrayOf("id"),
childColumns = arrayOf("importedFrom"),
onDelete = ForeignKey.CASCADE
)],
indices = [Index("importedFrom"), Index("host"), Index("host", "type")]
)
@TypeConverters(DnsTypeConverter::class)
data class DnsRule(
@PrimaryKey(autoGenerate = true) var id: Long = 0,
val type: Record.TYPE,
val host: String,
val ttl: Long,
val record: String
)
\ No newline at end of file
val record: String,
val importedFrom: Long? = null
) {
@PrimaryKey(autoGenerate = true) var id: Long = 0
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment