DatabaseModule.kt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Álvaro Brey
  5. * Copyright (C) 2022 Álvaro Brey
  6. * Copyright (C) 2022 Nextcloud GmbH
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. package com.nextcloud.client.database
  23. import android.content.Context
  24. import androidx.room.Room
  25. import com.nextcloud.client.core.Clock
  26. import com.nextcloud.client.database.migrations.RoomMigration
  27. import com.nextcloud.client.database.migrations.addLegacyMigrations
  28. import com.owncloud.android.db.ProviderMeta
  29. import dagger.Module
  30. import dagger.Provides
  31. import javax.inject.Singleton
  32. @Module
  33. class DatabaseModule {
  34. @Provides
  35. @Singleton
  36. @Suppress("Detekt.SpreadOperator") // forced by Room API
  37. fun database(context: Context, clock: Clock): NextcloudDatabase {
  38. return Room
  39. .databaseBuilder(context, NextcloudDatabase::class.java, ProviderMeta.DB_NAME)
  40. .addLegacyMigrations(clock)
  41. .addMigrations(RoomMigration())
  42. .fallbackToDestructiveMigration()
  43. .build()
  44. }
  45. }