Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 2b629c8b authored by Sunik Kupfer's avatar Sunik Kupfer Committed by GitHub
Browse files

Add comments on foreign key constraint enforcement (#1675)

* Add comments on foreign key constraint enforcement

* Fix grammar

* Add foreign key constraint comment to AppDatabase

* Update kdoc with better description
parent cd725479
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ abstract class DatabaseMigrationTest(
    /**
     * Used for testing the migration process from [toVersion]-1 to [toVersion].
     *
     * Note: SQLite's foreign key constraint enforcement is not enabled in tests. We need
     * to enable it ourselves using setting "PRAGMA foreign_keys=ON" directly after opening
     * a new database connection (works per connection). In tests it's usually more practical
     * not to do so, however. In production database connections room enables it for us.
     *
     * @param prepare      Callback to prepare the database. Will be run with database schema in version [toVersion] - 1.
     * @param validate     Callback to validate the migration result. Will be run with database schema in version [toVersion].
     */
@@ -61,6 +66,8 @@ abstract class DatabaseMigrationTest(
        // Prepare the database with the initial version.
        val dbName = "test"
        helper.createDatabase(dbName, version = toVersion - 1).apply {
            // We could enable foreign key constraint enforcement here
            // by setting "PRAGMA foreign_keys=ON".
            prepare(this)
            close()
        }
+7 −0
Original line number Diff line number Diff line
@@ -35,6 +35,13 @@ import dagger.hilt.components.SingletonComponent
import java.io.Writer
import javax.inject.Singleton

/**
 * The app database. Managed via android jetpack room. Room provides an abstraction
 * layer over SQLite.
 *
 * Note: In SQLite PRAGMA foreign_keys is off by default. Room activates it for
 * production (non-test) databases.
 */
@Database(entities = [
    Service::class,
    HomeSet::class,