diff --git a/db/migrations/1532468319_create_flip_kick_table.up.sql b/db/migrations/1532468319_create_flip_kick_table.up.sql index 5f698e9d..48c6d848 100644 --- a/db/migrations/1532468319_create_flip_kick_table.up.sql +++ b/db/migrations/1532468319_create_flip_kick_table.up.sql @@ -1,13 +1,14 @@ CREATE TABLE maker.flip_kick ( - db_id SERIAL PRIMARY KEY, - header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, - id NUMERIC NOT NULL UNIQUE, - lot NUMERIC, - bid NUMERIC, - gal VARCHAR, - "end" TIMESTAMP WITH TIME ZONE, - urn VARCHAR, - tab NUMERIC, - tx_idx INTEGER NOT NUll, - raw_log JSONB + id SERIAL PRIMARY KEY, + header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, + bid_id NUMERIC NOT NULL, + lot NUMERIC, + bid NUMERIC, + gal VARCHAR, + "end" TIMESTAMP WITH TIME ZONE, + urn VARCHAR, + tab NUMERIC, + tx_idx INTEGER NOT NUll, + raw_log JSONB, + UNIQUE (header_id, tx_idx) ); diff --git a/db/migrations/1534295712_create_tend_table.up.sql b/db/migrations/1534295712_create_tend_table.up.sql index 8b19cfea..a6dd18e8 100644 --- a/db/migrations/1534295712_create_tend_table.up.sql +++ b/db/migrations/1534295712_create_tend_table.up.sql @@ -1,5 +1,5 @@ CREATE TABLE maker.tend ( - db_id SERIAL PRIMARY KEY, + id SERIAL PRIMARY KEY, header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, bid_id NUMERIC NOT NULL UNIQUE, lot NUMERIC, @@ -7,5 +7,6 @@ CREATE TABLE maker.tend ( guy VARCHAR, tic NUMERIC, tx_idx INTEGER NOT NUll, - raw_log JSONB + raw_log JSONB, + UNIQUE (header_id, tx_idx) ); diff --git a/db/migrations/1534799167_create_dent_table.up.sql b/db/migrations/1534799167_create_dent_table.up.sql index eeb5c2b2..77a9af17 100644 --- a/db/migrations/1534799167_create_dent_table.up.sql +++ b/db/migrations/1534799167_create_dent_table.up.sql @@ -1,5 +1,5 @@ CREATE TABLE maker.dent ( - db_id SERIAL PRIMARY KEY, + id SERIAL PRIMARY KEY, header_id INTEGER NOT NULL REFERENCES headers (id) ON DELETE CASCADE, bid_id NUMERIC NOT NULL UNIQUE, lot NUMERIC, @@ -7,5 +7,6 @@ CREATE TABLE maker.dent ( guy BYTEA, tic NUMERIC, tx_idx INTEGER NOT NUll, - raw_log JSONB + raw_log JSONB, + UNIQUE (header_id, tx_idx) ); diff --git a/db/schema.sql b/db/schema.sql index 2bb736f4..2e9a909c 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -133,7 +133,7 @@ ALTER SEQUENCE maker.deal_id_seq OWNED BY maker.deal.id; -- CREATE TABLE maker.dent ( - db_id integer NOT NULL, + id integer NOT NULL, header_id integer NOT NULL, bid_id numeric NOT NULL, lot numeric, @@ -146,10 +146,10 @@ CREATE TABLE maker.dent ( -- --- Name: dent_db_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- Name: dent_id_seq; Type: SEQUENCE; Schema: maker; Owner: - -- -CREATE SEQUENCE maker.dent_db_id_seq +CREATE SEQUENCE maker.dent_id_seq AS integer START WITH 1 INCREMENT BY 1 @@ -159,10 +159,10 @@ CREATE SEQUENCE maker.dent_db_id_seq -- --- Name: dent_db_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- Name: dent_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - -- -ALTER SEQUENCE maker.dent_db_id_seq OWNED BY maker.dent.db_id; +ALTER SEQUENCE maker.dent_id_seq OWNED BY maker.dent.id; -- @@ -306,9 +306,9 @@ ALTER SEQUENCE maker.drip_file_vow_id_seq OWNED BY maker.drip_file_vow.id; -- CREATE TABLE maker.flip_kick ( - db_id integer NOT NULL, + id integer NOT NULL, header_id integer NOT NULL, - id numeric NOT NULL, + bid_id numeric NOT NULL, lot numeric, bid numeric, gal character varying, @@ -321,10 +321,10 @@ CREATE TABLE maker.flip_kick ( -- --- Name: flip_kick_db_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- Name: flip_kick_id_seq; Type: SEQUENCE; Schema: maker; Owner: - -- -CREATE SEQUENCE maker.flip_kick_db_id_seq +CREATE SEQUENCE maker.flip_kick_id_seq AS integer START WITH 1 INCREMENT BY 1 @@ -334,10 +334,10 @@ CREATE SEQUENCE maker.flip_kick_db_id_seq -- --- Name: flip_kick_db_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- Name: flip_kick_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - -- -ALTER SEQUENCE maker.flip_kick_db_id_seq OWNED BY maker.flip_kick.db_id; +ALTER SEQUENCE maker.flip_kick_id_seq OWNED BY maker.flip_kick.id; -- @@ -522,7 +522,7 @@ ALTER SEQUENCE maker.price_feeds_id_seq OWNED BY maker.price_feeds.id; -- CREATE TABLE maker.tend ( - db_id integer NOT NULL, + id integer NOT NULL, header_id integer NOT NULL, bid_id numeric NOT NULL, lot numeric, @@ -535,10 +535,10 @@ CREATE TABLE maker.tend ( -- --- Name: tend_db_id_seq; Type: SEQUENCE; Schema: maker; Owner: - +-- Name: tend_id_seq; Type: SEQUENCE; Schema: maker; Owner: - -- -CREATE SEQUENCE maker.tend_db_id_seq +CREATE SEQUENCE maker.tend_id_seq AS integer START WITH 1 INCREMENT BY 1 @@ -548,10 +548,10 @@ CREATE SEQUENCE maker.tend_db_id_seq -- --- Name: tend_db_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - +-- Name: tend_id_seq; Type: SEQUENCE OWNED BY; Schema: maker; Owner: - -- -ALTER SEQUENCE maker.tend_db_id_seq OWNED BY maker.tend.db_id; +ALTER SEQUENCE maker.tend_id_seq OWNED BY maker.tend.id; -- @@ -1005,10 +1005,10 @@ ALTER TABLE ONLY maker.deal ALTER COLUMN id SET DEFAULT nextval('maker.deal_id_s -- --- Name: dent db_id; Type: DEFAULT; Schema: maker; Owner: - +-- Name: dent id; Type: DEFAULT; Schema: maker; Owner: - -- -ALTER TABLE ONLY maker.dent ALTER COLUMN db_id SET DEFAULT nextval('maker.dent_db_id_seq'::regclass); +ALTER TABLE ONLY maker.dent ALTER COLUMN id SET DEFAULT nextval('maker.dent_id_seq'::regclass); -- @@ -1040,10 +1040,10 @@ ALTER TABLE ONLY maker.drip_file_vow ALTER COLUMN id SET DEFAULT nextval('maker. -- --- Name: flip_kick db_id; Type: DEFAULT; Schema: maker; Owner: - +-- Name: flip_kick id; Type: DEFAULT; Schema: maker; Owner: - -- -ALTER TABLE ONLY maker.flip_kick ALTER COLUMN db_id SET DEFAULT nextval('maker.flip_kick_db_id_seq'::regclass); +ALTER TABLE ONLY maker.flip_kick ALTER COLUMN id SET DEFAULT nextval('maker.flip_kick_id_seq'::regclass); -- @@ -1082,10 +1082,10 @@ ALTER TABLE ONLY maker.price_feeds ALTER COLUMN id SET DEFAULT nextval('maker.pr -- --- Name: tend db_id; Type: DEFAULT; Schema: maker; Owner: - +-- Name: tend id; Type: DEFAULT; Schema: maker; Owner: - -- -ALTER TABLE ONLY maker.tend ALTER COLUMN db_id SET DEFAULT nextval('maker.tend_db_id_seq'::regclass); +ALTER TABLE ONLY maker.tend ALTER COLUMN id SET DEFAULT nextval('maker.tend_id_seq'::regclass); -- @@ -1205,12 +1205,20 @@ ALTER TABLE ONLY maker.dent ADD CONSTRAINT dent_bid_id_key UNIQUE (bid_id); +-- +-- Name: dent dent_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.dent + ADD CONSTRAINT dent_header_id_tx_idx_key UNIQUE (header_id, tx_idx); + + -- -- Name: dent dent_pkey; Type: CONSTRAINT; Schema: maker; Owner: - -- ALTER TABLE ONLY maker.dent - ADD CONSTRAINT dent_pkey PRIMARY KEY (db_id); + ADD CONSTRAINT dent_pkey PRIMARY KEY (id); -- @@ -1278,11 +1286,11 @@ ALTER TABLE ONLY maker.drip_file_vow -- --- Name: flip_kick flip_kick_id_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- Name: flip_kick flip_kick_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - -- ALTER TABLE ONLY maker.flip_kick - ADD CONSTRAINT flip_kick_id_key UNIQUE (id); + ADD CONSTRAINT flip_kick_header_id_tx_idx_key UNIQUE (header_id, tx_idx); -- @@ -1290,7 +1298,7 @@ ALTER TABLE ONLY maker.flip_kick -- ALTER TABLE ONLY maker.flip_kick - ADD CONSTRAINT flip_kick_pkey PRIMARY KEY (db_id); + ADD CONSTRAINT flip_kick_pkey PRIMARY KEY (id); -- @@ -1381,12 +1389,20 @@ ALTER TABLE ONLY maker.tend ADD CONSTRAINT tend_bid_id_key UNIQUE (bid_id); +-- +-- Name: tend tend_header_id_tx_idx_key; Type: CONSTRAINT; Schema: maker; Owner: - +-- + +ALTER TABLE ONLY maker.tend + ADD CONSTRAINT tend_header_id_tx_idx_key UNIQUE (header_id, tx_idx); + + -- -- Name: tend tend_pkey; Type: CONSTRAINT; Schema: maker; Owner: - -- ALTER TABLE ONLY maker.tend - ADD CONSTRAINT tend_pkey PRIMARY KEY (db_id); + ADD CONSTRAINT tend_pkey PRIMARY KEY (id); -- diff --git a/pkg/transformers/flip_kick/converter.go b/pkg/transformers/flip_kick/converter.go index 96f4c32f..99a7212a 100644 --- a/pkg/transformers/flip_kick/converter.go +++ b/pkg/transformers/flip_kick/converter.go @@ -73,7 +73,7 @@ func (FlipKickConverter) ToModel(flipKick FlipKickEntity) (FlipKickModel, error) rawLogString := string(rawLogJson) return FlipKickModel{ - Id: id, + BidId: id, Lot: lot, Bid: bid, Gal: gal, diff --git a/pkg/transformers/flip_kick/converter_test.go b/pkg/transformers/flip_kick/converter_test.go index 579f0d1e..25e281dc 100644 --- a/pkg/transformers/flip_kick/converter_test.go +++ b/pkg/transformers/flip_kick/converter_test.go @@ -81,7 +81,7 @@ var _ = Describe("FlipKick Converter", func() { model, err := converter.ToModel(emptyEntity) Expect(err).NotTo(HaveOccurred()) - Expect(model.Id).To(Equal("1")) + Expect(model.BidId).To(Equal("1")) Expect(model.Lot).To(Equal(emptyString)) Expect(model.Bid).To(Equal(emptyString)) Expect(model.Gal).To(Equal(emptyAddressHex)) diff --git a/pkg/transformers/flip_kick/model.go b/pkg/transformers/flip_kick/model.go index 518ba767..88b13195 100644 --- a/pkg/transformers/flip_kick/model.go +++ b/pkg/transformers/flip_kick/model.go @@ -17,7 +17,7 @@ package flip_kick import "time" type FlipKickModel struct { - Id string + BidId string `db:"bid_id"` Lot string Bid string Gal string diff --git a/pkg/transformers/flip_kick/repository.go b/pkg/transformers/flip_kick/repository.go index 7f2f2dfb..0af06361 100644 --- a/pkg/transformers/flip_kick/repository.go +++ b/pkg/transformers/flip_kick/repository.go @@ -35,9 +35,9 @@ func NewFlipKickRepository(db *postgres.DB) FlipKickRepository { } func (fkr FlipKickRepository) Create(headerId int64, flipKick FlipKickModel) error { _, err := fkr.DB.Exec( - `INSERT into maker.flip_kick (header_id, id, lot, bid, gal, "end", urn, tab, tx_idx, raw_log) + `INSERT into maker.flip_kick (header_id, bid_id, lot, bid, gal, "end", urn, tab, tx_idx, raw_log) VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`, - headerId, flipKick.Id, flipKick.Lot, flipKick.Bid, flipKick.Gal, flipKick.End, flipKick.Urn, flipKick.Tab, flipKick.TransactionIndex, flipKick.Raw, + headerId, flipKick.BidId, flipKick.Lot, flipKick.Bid, flipKick.Gal, flipKick.End, flipKick.Urn, flipKick.Tab, flipKick.TransactionIndex, flipKick.Raw, ) return err } diff --git a/pkg/transformers/flip_kick/repository_test.go b/pkg/transformers/flip_kick/repository_test.go index 7296c908..a7c1624b 100644 --- a/pkg/transformers/flip_kick/repository_test.go +++ b/pkg/transformers/flip_kick/repository_test.go @@ -64,7 +64,7 @@ var _ = Describe("FlipKick Repository", func() { err = flipKickRepository.DB.QueryRowx(`SELECT * FROM maker.flip_kick`).StructScan(&dbResult) Expect(err).NotTo(HaveOccurred()) Expect(dbResult.HeaderId).To(Equal(headerId)) - Expect(dbResult.Id).To(Equal(flipKick.Id)) + Expect(dbResult.BidId).To(Equal(flipKick.BidId)) Expect(dbResult.Lot).To(Equal(flipKick.Lot)) Expect(dbResult.Bid).To(Equal(flipKick.Bid)) Expect(dbResult.Gal).To(Equal(flipKick.Gal)) diff --git a/pkg/transformers/test_data/flip_kick.go b/pkg/transformers/test_data/flip_kick.go index c9c2a99c..90ef6a87 100644 --- a/pkg/transformers/test_data/flip_kick.go +++ b/pkg/transformers/test_data/flip_kick.go @@ -80,7 +80,7 @@ var FlipKickEntity = flip_kick.FlipKickEntity{ } var FlipKickModel = flip_kick.FlipKickModel{ - Id: idString, + BidId: idString, Lot: lotString, Bid: bidString, Gal: gal, @@ -92,7 +92,7 @@ var FlipKickModel = flip_kick.FlipKickModel{ } type FlipKickDBRow struct { - DbID int64 `db:"db_id"` + ID int64 HeaderId int64 `db:"header_id"` flip_kick.FlipKickModel }