-
Notifications
You must be signed in to change notification settings - Fork 97
add balance audit table #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| CREATE TABLE `balance_audit` ( | ||
| `airline` int(11) NOT NULL, | ||
| `cycle` int(11) NOT NULL, | ||
| `balance` mediumtext, | ||
| UNIQUE KEY `balance_audit_UN` (`airline`,`cycle`), | ||
| CONSTRAINT `balance_audit_FK` FOREIGN KEY (`airline`) REFERENCES `airline` (`id`) ON DELETE CASCADE ON UPDATE CASCADE | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,15 @@ object AirlineSource { | |
| updateStatement.setInt(2, airlineId) | ||
| updateStatement.executeUpdate() | ||
| updateStatement.close() | ||
|
|
||
| // update balance audit table | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm kinda on the fence for this, in a way it's nice that :
But the cons are:
I lean towards setting it in the |
||
| val insertToBalanceAuditStatement = connection.prepareStatement( | ||
| s"REPLACE INTO $BALANCE_AUDIT (airline, cycle, balance) VALUES (?, (SELECT cycle + 1 FROM cycle), (SELECT balance FROM $AIRLINE_INFO_TABLE WHERE airline = ?))") | ||
| insertToBalanceAuditStatement.setInt(1, airlineId) | ||
| insertToBalanceAuditStatement.setInt(2, airlineId) | ||
| insertToBalanceAuditStatement.executeQuery(); | ||
| insertToBalanceAuditStatement.close(); | ||
|
|
||
| AirlineCache.invalidateAirline(airlineId) | ||
| } finally { | ||
| connection.close() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ object Constants { | |
| val AIRLINE_CASH_FLOW_ITEM_TABLE = "airline_cash_flow_item" | ||
| val AIRLINE_BASE_SPECIALIZATION_TABLE = "airline_base_specialization" | ||
| val AIRLINE_REPUTATION_BREAKDOWN = "airline_reputation_breakdown" | ||
| val BALANCE_AUDIT = "balance_audit" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small nit - let's name this val |
||
|
|
||
|
|
||
| val INCOME_TABLE = "income" | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -37,7 +37,13 @@ object CycleSource { | |||
| insertStatement.setInt(1, cycle) | ||||
| insertStatement.executeUpdate() | ||||
| insertStatement.close() | ||||
|
|
||||
|
|
||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the setCycle w/o side effects. Currently we purge stuff on the cycle simulation end :
But i think it's probably better to do it at the |
||||
| // also clean up old (-48) balance audit entries | ||||
| val cleanupStatement = connection.prepareStatement(s"DELETE FROM $BALANCE_AUDIT WHERE cycle <= ?") | ||||
| cleanupStatement.setInt(1, cycle - 48) | ||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the cost is very low, we probably want to keep balance for way longer, like maybe 1000 cycles are okay |
||||
| cleanupStatement.executeQuery() | ||||
| cleanupStatement.close() | ||||
|
|
||||
| connection.commit() | ||||
| } finally { | ||||
| connection.close() | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,6 +313,7 @@ object Meta { | |
| createIp(connection) | ||
| createAdminLog(connection) | ||
| createUserUuid(connection) | ||
| createBalanceAudit(connection) | ||
|
|
||
| statement = connection.prepareStatement("CREATE TABLE " + AIRPORT_CITY_SHARE_TABLE + "(" + | ||
| "airport INTEGER," + | ||
|
|
@@ -1916,6 +1917,25 @@ object Meta { | |
| statement.close() | ||
| } | ||
|
|
||
| def createBalanceAudit(connection: Connection): Unit = { | ||
| var statement = connection.prepareStatement(s"DROP TABLE IF EXISTS $BALANCE_AUDIT") | ||
| statement.execute() | ||
| statement.close() | ||
|
|
||
| val sql = s""" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks nicer than my other sql statements 😊 |
||
| |CREATE TABLE `$BALANCE_AUDIT` ( | ||
| | `airline` int(11) NOT NULL, | ||
| | `cycle` int(11) NOT NULL, | ||
| | `balance` mediumtext, | ||
| | UNIQUE KEY `balance_audit_UN` (`airline`,`cycle`), | ||
| | CONSTRAINT `balance_audit_FK` FOREIGN KEY (`$AIRLINE_TABLE`) REFERENCES `airline` (`id`) ON DELETE CASCADE ON UPDATE CASCADE | ||
| |) | ||
| |""".stripMargin | ||
| statement = connection.prepareStatement(sql) | ||
| statement.execute() | ||
| statement.close() | ||
| } | ||
|
|
||
| def createAdminLog(connection : Connection) { | ||
| var statement = connection.prepareStatement("DROP TABLE IF EXISTS " + ADMIN_LOG_TABLE) | ||
| statement.execute() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah forgot to mention, if it's new table, we dun need a script here . As a dev, i can just run airline-data/src/main/scala/com/patson/data/QuickCreateSchema.scala :)