Skip to content

Commit

Permalink
Add new properties to Quotes table, add migration for that
Browse files Browse the repository at this point in the history
  • Loading branch information
premnirmal committed Jun 16, 2022
1 parent bcae321 commit b2f1046
Show file tree
Hide file tree
Showing 12 changed files with 390 additions and 17 deletions.
8 changes: 7 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ android {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}

kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
}
}
}

sourceSets {
Expand Down Expand Up @@ -193,7 +199,7 @@ ext {
OKHTTP_VERSION = "4.9.0"
ROBOLECTRIC_VERSION = "4.3.1"
COROUTINES_VERSION = "1.6.0"
ROOM_VERSION = "2.4.1"
ROOM_VERSION = "2.4.2"
WORK_VERSION = "2.7.1"
}

Expand Down
260 changes: 260 additions & 0 deletions app/schemas/com.github.premnirmal.ticker.repo.QuotesDB/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
{
"formatVersion": 1,
"database": {
"version": 3,
"identityHash": "ded8ebb6cda3d9b4d96eb448091cd1b3",
"entities": [
{
"tableName": "QuoteRow",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`symbol` TEXT NOT NULL, `name` TEXT NOT NULL, `last_trade_price` REAL NOT NULL, `change_percent` REAL NOT NULL, `change` REAL NOT NULL, `exchange` TEXT NOT NULL, `currency` TEXT NOT NULL, `is_post_market` INTEGER NOT NULL, `annual_dividend_rate` REAL NOT NULL, `annual_dividend_yield` REAL NOT NULL, `dayHigh` REAL, `dayLow` REAL, `previousClose` REAL NOT NULL, `open` REAL, `regularMarketVolume` REAL, `peRatio` REAL, `fiftyTwoWeekLowChange` REAL, `fiftyTwoWeekLowChangePercent` REAL, `fiftyTwoWeekHighChange` REAL, `fiftyTwoWeekHighChangePercent` REAL, `fiftyTwoWeekLow` REAL, `fiftyTwoWeekHigh` REAL, `dividendDate` REAL, `earningsDate` REAL, `marketCap` REAL, PRIMARY KEY(`symbol`))",
"fields": [
{
"fieldPath": "symbol",
"columnName": "symbol",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "lastTradePrice",
"columnName": "last_trade_price",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "changeInPercent",
"columnName": "change_percent",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "change",
"columnName": "change",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "stockExchange",
"columnName": "exchange",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "currency",
"columnName": "currency",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isPostMarket",
"columnName": "is_post_market",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "annualDividendRate",
"columnName": "annual_dividend_rate",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "annualDividendYield",
"columnName": "annual_dividend_yield",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "dayHigh",
"columnName": "dayHigh",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "dayLow",
"columnName": "dayLow",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "previousClose",
"columnName": "previousClose",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "open",
"columnName": "open",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "regularMarketVolume",
"columnName": "regularMarketVolume",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "peRatio",
"columnName": "peRatio",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekLowChange",
"columnName": "fiftyTwoWeekLowChange",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekLowChangePercent",
"columnName": "fiftyTwoWeekLowChangePercent",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekHighChange",
"columnName": "fiftyTwoWeekHighChange",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekHighChangePercent",
"columnName": "fiftyTwoWeekHighChangePercent",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekLow",
"columnName": "fiftyTwoWeekLow",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "fiftyTwoWeekHigh",
"columnName": "fiftyTwoWeekHigh",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "dividendDate",
"columnName": "dividendDate",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "earningsDate",
"columnName": "earningsDate",
"affinity": "REAL",
"notNull": false
},
{
"fieldPath": "marketCap",
"columnName": "marketCap",
"affinity": "REAL",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"symbol"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "HoldingRow",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `quote_symbol` TEXT NOT NULL, `shares` REAL NOT NULL, `price` REAL NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "quoteSymbol",
"columnName": "quote_symbol",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "shares",
"columnName": "shares",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "price",
"columnName": "price",
"affinity": "REAL",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "PropertiesRow",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `properties_quote_symbol` TEXT NOT NULL, `notes` TEXT NOT NULL, `alert_above` REAL NOT NULL, `alert_below` REAL NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "quoteSymbol",
"columnName": "properties_quote_symbol",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "notes",
"columnName": "notes",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "alertAbove",
"columnName": "alert_above",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "alertBelow",
"columnName": "alert_below",
"affinity": "REAL",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"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, 'ded8ebb6cda3d9b4d96eb448091cd1b3')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.github.premnirmal.ticker.repo.QuoteDao
import com.github.premnirmal.ticker.repo.QuotesDB
import com.github.premnirmal.ticker.repo.StocksStorage
import com.github.premnirmal.ticker.repo.migrations.MIGRATION_1_2
import com.github.premnirmal.ticker.repo.migrations.MIGRATION_2_3
import com.github.premnirmal.ticker.widget.WidgetDataProvider
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -61,6 +62,7 @@ class AppModule(private val app: StocksApp) {
QuotesDB::class.java, "quotes-db"
)
.addMigrations(MIGRATION_1_2)
.addMigrations(MIGRATION_2_3)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ class DbViewerViewModel(application: Application) : AndroidViewModel(application
<th>Symbol</th><th>Name</th><th>Last&nbsp;trade&nbsp;price</th>
<th>Change</th><th>Change %</th><th>Exchange</th>
<th>Currency</th><th>Dividend</th>
<th>annualDividendRate</th>
<th>annualDividendYield</th>
<th>dayHigh</th>
<th>dayLow</th>
<th>previousClose</th>
<th>open</th>
<th>regularMarketVolume</th>
<th>peRatio</th>
<th>fiftyTwoWeekLowChange</th>
<th>fiftyTwoWeekLowChangePercent</th>
<th>fiftyTwoWeekHighChange</th>
<th>fiftyTwoWeekHighChangePercent</th>
<th>fiftyTwoWeekLow</th>
<th>fiftyTwoWeekHigh</th>
<th>dividendDate</th>
<th>earningsDate</th>
<th>marketCap</th>
</tr>
"""
)
Expand Down Expand Up @@ -112,6 +129,23 @@ class DbViewerViewModel(application: Application) : AndroidViewModel(application
"<td></td>"
}
)
.append("<td>${quote.annualDividendRate}</td>")
.append("<td>${quote.annualDividendYield}</td>")
.append("<td>${quote.dayHigh}</td>")
.append("<td>${quote.dayLow}</td>")
.append("<td>${quote.previousClose}</td>")
.append("<td>${quote.open}</td>")
.append("<td>${quote.regularMarketVolume}</td>")
.append("<td>${quote.peRatio}</td>")
.append("<td>${quote.fiftyTwoWeekLowChange}</td>")
.append("<td>${quote.fiftyTwoWeekLowChangePercent}</td>")
.append("<td>${quote.fiftyTwoWeekHighChange}</td>")
.append("<td>${quote.fiftyTwoWeekHighChangePercent}</td>")
.append("<td>${quote.fiftyTwoWeekLow}</td>")
.append("<td>${quote.fiftyTwoWeekHigh}</td>")
.append("<td>${quote.dividendDate}</td>")
.append("<td>${quote.earningsDate}</td>")
.append("<td>${quote.marketCap}</td>")
.append("</tr>")

val holdings = it.holdings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import com.github.premnirmal.ticker.repo.data.PropertiesRow
import com.github.premnirmal.ticker.repo.data.QuoteRow

@Database(
entities = [QuoteRow::class, HoldingRow::class, PropertiesRow::class], version = 2,
entities = [QuoteRow::class, HoldingRow::class, PropertiesRow::class],
version = 3,
exportSchema = true
)
abstract class QuotesDB : RoomDatabase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ class StocksStorage {
return QuoteRow(
this.symbol, this.name, this.lastTradePrice, this.changeInPercent,
this.change, this.stockExchange, this.currencyCode,
this.isPostMarket, this.annualDividendRate, this.annualDividendYield
this.isPostMarket, this.annualDividendRate, this.annualDividendYield,
this.dayHigh, this.dayLow, this.previousClose, this.open,
this.regularMarketVolume?.toFloat(), this.trailingPE,
this.fiftyTwoWeekLowChange, this.fiftyTwoWeekLowChangePercent,
this.fiftyTwoWeekHighChange, this.fiftyTwoWeekHighChangePercent,
this.fiftyTwoWeekLow, this.fiftyTwoWeekHigh,
this.dividendDate?.toFloat(),
this.earningsTimestamp?.toFloat(),
this.marketCap?.toFloat()
)
}

Expand All @@ -151,7 +159,21 @@ class StocksStorage {
quote.isPostMarket = this.isPostMarket
quote.annualDividendRate = this.annualDividendRate
quote.annualDividendYield = this.annualDividendYield

quote.dayHigh = this.dayHigh
quote.dayLow = this.dayLow
quote.previousClose = this.previousClose
quote.open = this.open
quote.regularMarketVolume = this.regularMarketVolume?.toLong()
quote.trailingPE = this.peRatio
quote.fiftyTwoWeekLowChange = this.fiftyTwoWeekLowChange
quote.fiftyTwoWeekLowChangePercent = this.fiftyTwoWeekLowChangePercent
quote.fiftyTwoWeekHighChange = this.fiftyTwoWeekHighChange
quote.fiftyTwoWeekHighChangePercent = this.fiftyTwoWeekHighChangePercent
quote.fiftyTwoWeekLow = this.fiftyTwoWeekLow
quote.fiftyTwoWeekHigh = this.fiftyTwoWeekHigh
quote.dividendDate = this.dividendDate?.toLong()
quote.earningsTimestamp = this.earningsDate?.toLong()
quote.marketCap = this.marketCap?.toLong()
return quote
}

Expand Down
Loading

0 comments on commit b2f1046

Please sign in to comment.