]> git.ktnx.net Git - mobile-ledger.git/commitdiff
drop deprecation from profiles.uuid, make not null
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Aug 2021 13:43:04 +0000 (16:43 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Aug 2021 13:43:04 +0000 (16:43 +0300)
will be used when importing profiles from exported JSON configuration

app/src/main/java/net/ktnx/mobileledger/db/DB.java
app/src/main/java/net/ktnx/mobileledger/db/Profile.java
app/src/main/res/raw/db_64.sql [new file with mode: 0644]

index b03faa62fbb1d19b9e75a2c8ce1a2b33a49c54a4..7de2231d8dbb4f1ecd44bc64388b69a9715cf8dd 100644 (file)
@@ -58,7 +58,7 @@ import static net.ktnx.mobileledger.utils.Logger.debug;
                       TransactionAccount.class
           })
 abstract public class DB extends RoomDatabase {
-    public static final int REVISION = 63;
+    public static final int REVISION = 64;
     public static final String DB_NAME = "MoLe.db";
     public static final MutableLiveData<Boolean> initComplete = new MutableLiveData<>(false);
     private static DB instance;
@@ -79,7 +79,8 @@ abstract public class DB extends RoomDatabase {
                                     multiVersionMigration(34, 40), singleVersionMigration(41),
                                     multiVersionMigration(41, 58), singleVersionMigration(59),
                                     singleVersionMigration(60), singleVersionMigration(61),
-                                    singleVersionMigration(62), singleVersionMigration(63)
+                                    singleVersionMigration(62), singleVersionMigration(63),
+                                    singleVersionMigration(64)
                     })
                    .addCallback(new Callback() {
                        @Override
index 030ae1ba51d5215d1d4d5b04b6592317ba64e05c..a3ed1806e0a86ddf93dd11f77342bfd04ea614f4 100644 (file)
@@ -23,6 +23,7 @@ import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.room.ColumnInfo;
 import androidx.room.Entity;
+import androidx.room.Index;
 import androidx.room.PrimaryKey;
 import androidx.room.Transaction;
 
@@ -33,7 +34,10 @@ import net.ktnx.mobileledger.utils.Misc;
 
 import org.jetbrains.annotations.NotNull;
 
-@Entity(tableName = "profiles")
+import java.util.UUID;
+
+@Entity(tableName = "profiles",
+        indices = {@Index(name = "profiles_uuid_idx", unique = true, value = "uuid")})
 public class Profile {
     public static final long NO_PROFILE_ID = 0;
     @ColumnInfo
@@ -42,8 +46,9 @@ public class Profile {
     @NonNull
     @ColumnInfo
     private String name = "";
-    @ColumnInfo(name = "deprecated_uuid")
-    private String deprecatedUUID;
+    @NonNull
+    @ColumnInfo()
+    private String uuid;
     @NonNull
     @ColumnInfo
     private String url = "";
@@ -77,11 +82,15 @@ public class Profile {
     private int detectedVersionMajor;
     @ColumnInfo(name = "detected_version_minor")
     private int detectedVersionMinor;
-    public String getDeprecatedUUID() {
-        return deprecatedUUID;
+    public Profile() {
+        uuid = UUID.randomUUID()
+                   .toString();
+    }
+    public String getUuid() {
+        return uuid;
     }
-    public void setDeprecatedUUID(String deprecatedUUID) {
-        this.deprecatedUUID = deprecatedUUID;
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
     }
     public long getId() {
         return id;
@@ -204,8 +213,7 @@ public class Profile {
         if (!(o instanceof Profile))
             return false;
         Profile p = (Profile) o;
-        return id == p.id && Misc.equalStrings(name, p.name) &&
-               Misc.equalStrings(deprecatedUUID, p.deprecatedUUID) &&
+        return id == p.id && Misc.equalStrings(name, p.name) && Misc.equalStrings(uuid, p.uuid) &&
                Misc.equalStrings(url, p.url) && useAuthentication == p.useAuthentication &&
                Misc.equalStrings(authUser, p.authUser) &&
                Misc.equalStrings(authPassword, p.authPassword) && orderNo == p.orderNo &&
diff --git a/app/src/main/res/raw/db_64.sql b/app/src/main/res/raw/db_64.sql
new file mode 100644 (file)
index 0000000..e463e94
--- /dev/null
@@ -0,0 +1,62 @@
+-- Copyright © 2021 Damyan Ivanov.
+-- This file is part of MoLe.
+-- MoLe is free software: you can distribute it and/or modify it
+-- under the term of the GNU General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your opinion), any later version.
+--
+-- MoLe is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License terms for details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+
+-- migrate from revision 63 to revision 64
+
+-- pragmas need to be outside of transaction control
+-- foreign_keys is needed so that foreign key constraints are redirected
+
+commit transaction;
+pragma foreign_keys = off;
+
+begin transaction;
+
+-- profiles
+CREATE TABLE profiles_new (
+id INTEGER NOT NULL PRIMARY KEY,
+uuid TEXT NOT NULL,
+name TEXT NOT NULL,
+url TEXT NOT NULL,
+use_authentication INTEGER NOT NULL,
+auth_user TEXT,
+auth_password TEXT,
+order_no INTEGER NOT NULL,
+permit_posting INTEGER NOT NULL,
+theme INTEGER NOT NULL DEFAULT -1,
+preferred_accounts_filter TEXT,
+future_dates INTEGER NOT NULL,
+api_version INTEGER NOT NULL,
+show_commodity_by_default INTEGER NOT NULL,
+default_commodity TEXT,
+show_comments_by_default INTEGER NOT NULL DEFAULT 1,
+detected_version_pre_1_19 INTEGER NOT NULL,
+detected_version_major INTEGER NOT NULL,
+detected_version_minor INTEGER NOT NULL);
+
+insert into profiles_new(
+       uuid, name, url, use_authentication, auth_user, auth_password,
+       order_no, permit_posting, theme, preferred_accounts_filter, future_dates, api_version,
+       show_commodity_by_default, default_commodity, show_comments_by_default, detected_version_pre_1_19,
+       detected_version_major, detected_version_minor)
+select coalesce(deprecated_uuid, random()), name, url, use_authentication, auth_user, auth_password,
+       order_no, permit_posting, theme, preferred_accounts_filter, future_dates, api_version,
+       show_commodity_by_default, default_commodity, show_comments_by_default, detected_version_pre_1_19,
+       detected_version_major, detected_version_minor
+from profiles;
+
+drop table profiles;
+alter table profiles_new rename to profiles;
+
+create unique index profiles_uuid_idx on profiles(uuid);
\ No newline at end of file