]> git.ktnx.net Git - mobile-ledger.git/commitdiff
describe description_history to Room
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 19 Feb 2021 16:20:13 +0000 (16:20 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 1 Mar 2021 06:00:42 +0000 (06:00 +0000)
app/schemas/net.ktnx.mobileledger.db.DB/58.json
app/src/main/java/net/ktnx/mobileledger/db/DB.java
app/src/main/java/net/ktnx/mobileledger/db/DescriptionHistory.java [new file with mode: 0644]
app/src/main/res/raw/create_db.sql
app/src/main/res/raw/sql_58.sql

index 5ea56419daaaaff162ce92218fa5d870678620e1..c4e6131319a40aeef18ebde15693ef0afe3f6125 100644 (file)
@@ -2,7 +2,7 @@
   "formatVersion": 1,
   "database": {
     "version": 58,
   "formatVersion": 1,
   "database": {
     "version": 58,
-    "identityHash": "ce42602c9c1d3edae4cb67fa54bc6f76",
+    "identityHash": "00d9b541473347c65a90e47ce9072436",
     "entities": [
       {
         "tableName": "templates",
     "entities": [
       {
         "tableName": "templates",
         },
         "indices": [],
         "foreignKeys": []
         },
         "indices": [],
         "foreignKeys": []
+      },
+      {
+        "tableName": "description_history",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`description` TEXT NOT NULL COLLATE NOCASE, `description_upper` TEXT NOT NULL, `generation` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`description`))",
+        "fields": [
+          {
+            "fieldPath": "description",
+            "columnName": "description",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "descriptionUpper",
+            "columnName": "description_upper",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "generation",
+            "columnName": "generation",
+            "affinity": "INTEGER",
+            "notNull": true,
+            "defaultValue": "0"
+          }
+        ],
+        "primaryKey": {
+          "columnNames": [
+            "description"
+          ],
+          "autoGenerate": false
+        },
+        "indices": [],
+        "foreignKeys": []
+      },
+      {
+        "tableName": "transactions",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`profile` TEXT NOT NULL, `id` INTEGER NOT NULL, `data_hash` TEXT NOT NULL, `year` INTEGER NOT NULL, `month` INTEGER NOT NULL, `day` INTEGER NOT NULL, `description` TEXT NOT NULL COLLATE NOCASE, `comment` TEXT, `generation` INTEGER NOT NULL, PRIMARY KEY(`profile`, `id`))",
+        "fields": [
+          {
+            "fieldPath": "profile",
+            "columnName": "profile",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "id",
+            "columnName": "id",
+            "affinity": "INTEGER",
+            "notNull": true
+          },
+          {
+            "fieldPath": "dataHash",
+            "columnName": "data_hash",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "year",
+            "columnName": "year",
+            "affinity": "INTEGER",
+            "notNull": true
+          },
+          {
+            "fieldPath": "month",
+            "columnName": "month",
+            "affinity": "INTEGER",
+            "notNull": true
+          },
+          {
+            "fieldPath": "day",
+            "columnName": "day",
+            "affinity": "INTEGER",
+            "notNull": true
+          },
+          {
+            "fieldPath": "description",
+            "columnName": "description",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "comment",
+            "columnName": "comment",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "generation",
+            "columnName": "generation",
+            "affinity": "INTEGER",
+            "notNull": true
+          }
+        ],
+        "primaryKey": {
+          "columnNames": [
+            "profile",
+            "id"
+          ],
+          "autoGenerate": false
+        },
+        "indices": [
+          {
+            "name": "un_transactions_data_hash",
+            "unique": true,
+            "columnNames": [
+              "profile",
+              "data_hash"
+            ],
+            "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `un_transactions_data_hash` ON `${TABLE_NAME}` (`profile`, `data_hash`)"
+          },
+          {
+            "name": "idx_transaction_description",
+            "unique": false,
+            "columnNames": [
+              "description"
+            ],
+            "createSql": "CREATE INDEX IF NOT EXISTS `idx_transaction_description` ON `${TABLE_NAME}` (`description`)"
+          }
+        ],
+        "foreignKeys": []
       }
     ],
     "views": [],
     "setupQueries": [
       "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
       }
     ],
     "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, 'ce42602c9c1d3edae4cb67fa54bc6f76')"
+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '00d9b541473347c65a90e47ce9072436')"
     ]
   }
 }
\ No newline at end of file
     ]
   }
 }
\ No newline at end of file
index b66552fb460edcab4233a9129ef587d8213b085f..630c5b272a64002061908d5db2cac881021b6f72 100644 (file)
@@ -33,7 +33,8 @@ import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
 
 @Database(version = 58,
           entities = {TemplateHeader.class, TemplateAccount.class, Currency.class, Account.class,
 
 @Database(version = 58,
           entities = {TemplateHeader.class, TemplateAccount.class, Currency.class, Account.class,
-                      Profile.class, Option.class, AccountValue.class
+                      Profile.class, Option.class, AccountValue.class, DescriptionHistory.class,
+                      Transaction.class
           })
 abstract public class DB extends RoomDatabase {
     private static DB instance;
           })
 abstract public class DB extends RoomDatabase {
     private static DB instance;
diff --git a/app/src/main/java/net/ktnx/mobileledger/db/DescriptionHistory.java b/app/src/main/java/net/ktnx/mobileledger/db/DescriptionHistory.java
new file mode 100644 (file)
index 0000000..0e3b246
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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/>.
+ */
+
+package net.ktnx.mobileledger.db;
+
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
+import androidx.room.Entity;
+
+@Entity(tableName = "description_history", primaryKeys = {"description"})
+public class DescriptionHistory {
+    @ColumnInfo(collate = ColumnInfo.NOCASE)
+    @NonNull
+    private String description;
+    @ColumnInfo(name = "description_upper")
+    @NonNull
+    private String descriptionUpper;
+    @ColumnInfo(defaultValue = "0")
+    private int generation = 0;
+    @NonNull
+    public String getDescription() {
+        return description;
+    }
+    public void setDescription(@NonNull String description) {
+        this.description = description;
+    }
+    @NonNull
+    public String getDescriptionUpper() {
+        return descriptionUpper;
+    }
+    public void setDescriptionUpper(@NonNull String descriptionUpper) {
+        this.descriptionUpper = descriptionUpper;
+    }
+    public int getGeneration() {
+        return generation;
+    }
+    public void setGeneration(int generation) {
+        this.generation = generation;
+    }
+}
index c05216a7dcf0d8fbbd0a848b1febb2fdcbeaaebb..9a0ccbd6318a01de1c3bf1a7a444090d42efe7f5 100644 (file)
@@ -47,8 +47,11 @@ create table account_values(
  generation integer not null default 0,
  primary key(profile, account, currency));
 
  generation integer not null default 0,
  primary key(profile, account, currency));
 
-create table description_history(description varchar not null primary key, description_upper varchar, generation integer default 0);
-create unique index un_description_history on description_history(description_upper);
+create table description_history(description varchar collate NOCASE not null,
+ description_upper varchar not null,
+ generation integer not null default 0,
+ primary key(description));
+
 create table transactions(profile varchar not null, id integer not null, data_hash varchar not null, year integer not null, month integer not null, day integer not null, description varchar not null, comment varchar, generation integer default 0);
 create unique index un_transactions_id on transactions(profile,id);
 create unique index un_transactions_data_hash on transactions(profile,data_hash);
 create table transactions(profile varchar not null, id integer not null, data_hash varchar not null, year integer not null, month integer not null, day integer not null, description varchar not null, comment varchar, generation integer default 0);
 create unique index un_transactions_id on transactions(profile,id);
 create unique index un_transactions_data_hash on transactions(profile,data_hash);
index 23f6502a232db82a4a323cc78adc323eaf69a040..ab3d08865146330ed513aab66d2e9c2c837e05ff 100644 (file)
@@ -81,6 +81,17 @@ from account_values;
 drop table account_values;
 alter table account_values_new rename to account_values;
 
 drop table account_values;
 alter table account_values_new rename to account_values;
 
+create table description_history_new(
+ description varchar collate NOCASE not null primary key,
+ description_upper varchar not null,
+ generation integer not null default 0,
+ primary key(description));
+
+insert into description_history_new(description, description_upper, generation)
+select description, description_upper, generation from description_history;
+
+drop table description_history;
+alter table description_history_new rename to description_history;
 
 COMMIT TRANSACTION;
 
 
 COMMIT TRANSACTION;