Skip to content

Commit 9d56dbb

Browse files
committed
Improved SqlSchema.cs in such way that column/table names are now stored as constants.
1 parent bfc97f9 commit 9d56dbb

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

Database/SqlSchema.cs

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,53 @@ namespace Database
44
{
55
public class SqlSchema
66
{
7-
// TODO column names into constants
7+
public const string TablePortfolios = "portfolios";
8+
public const string PortfoliosId = "id";
9+
public const string PortfoliosName = "name";
10+
public const string PortfoliosDescription = "description";
11+
public const string PortfoliosCurrencyCode = "currency_code";
12+
13+
public const string TablePortfolioEntries = "portfolio_entries";
14+
public const string PortfolioEntriesId = "id";
15+
public const string PortfolioEntriesSymbol = "symbol";
16+
public const string PortfolioEntriesPortfolioId = "portfolio_id";
17+
18+
public const string TableMarketOrders = "market_orders";
19+
public const string MarketOrdersId = "id";
20+
public const string MarketOrdersFilledPrice = "filled_price";
21+
public const string MarketOrdersFee = "fee";
22+
public const string MarketOrdersSize = "size";
23+
public const string MarketOrdersDate = "date";
24+
public const string MarketOrdersBuy = "buy";
25+
public const string MarketOrdersPortfolioEntryId = "portfolio_entry_id";
26+
827
public static void Init(SqlKataDatabase db)
928
{
10-
db.Get().Statement(@"
29+
db.Get().Statement($@"
1130
12-
CREATE TABLE IF NOT EXISTS portfolios (
13-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
14-
name TEXT NOT NULL,
15-
description TEXT NOT NULL,
16-
currency_code INTEGER NOT NULL
31+
CREATE TABLE IF NOT EXISTS {TablePortfolios} (
32+
{PortfoliosId} INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
33+
{PortfoliosName} TEXT NOT NULL,
34+
{PortfoliosDescription} TEXT NOT NULL,
35+
{PortfoliosCurrencyCode} INTEGER NOT NULL
1736
);
1837
19-
CREATE TABLE IF NOT EXISTS portfolio_entries (
20-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
21-
symbol TEXT NOT NULL,
22-
portfolio_id INTEGER NOT NULL,
23-
FOREIGN KEY(portfolio_id) REFERENCES portfolios(id)
38+
CREATE TABLE IF NOT EXISTS {TablePortfolioEntries} (
39+
{PortfolioEntriesId} INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
40+
{PortfolioEntriesSymbol} TEXT NOT NULL,
41+
{PortfolioEntriesPortfolioId} INTEGER NOT NULL,
42+
FOREIGN KEY({PortfolioEntriesPortfolioId}) REFERENCES {TablePortfolios}(id)
2443
);
2544
26-
CREATE TABLE IF NOT EXISTS market_orders (
27-
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
28-
filled_price INTEGER NOT NULL,
29-
fee INTEGER NOT NULL,
30-
size INTEGER NOT NULL,
31-
date INTEGER NOT NULL,
32-
buy INTEGER NOT NULL,
33-
portfolio_entry_id INTEGER NOT NULL,
34-
FOREIGN KEY(portfolio_entry_id) REFERENCES portfolio_entries(id)
45+
CREATE TABLE IF NOT EXISTS {TableMarketOrders} (
46+
{MarketOrdersId} INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
47+
{MarketOrdersFilledPrice} INTEGER NOT NULL,
48+
{MarketOrdersFee} INTEGER NOT NULL,
49+
{MarketOrdersSize} INTEGER NOT NULL,
50+
{MarketOrdersDate} INTEGER NOT NULL,
51+
{MarketOrdersBuy} INTEGER NOT NULL,
52+
{MarketOrdersPortfolioEntryId} INTEGER NOT NULL,
53+
FOREIGN KEY({MarketOrdersPortfolioEntryId}) REFERENCES {TablePortfolioEntries}(id)
3554
);
3655
3756
");

0 commit comments

Comments
 (0)