Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pykern/sql_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ def _col(col_spec):
a = [col_spec.pkdel("name"), col_spec.pkdel("stype")]
if a[1] is _PRIMARY_ID_STYPE:
_col_primary_id(col_spec, a)
elif col_spec.get("primary_key"):
if col_spec.get("primary_key") and a[0] not in self._primary_keys:
self._primary_keys.append(a[0])
if col_spec.pkdel("foreign"):
a.append(
Expand Down
8 changes: 8 additions & 0 deletions tests/sql_db_data/schema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ t4_pk2 VARCHAR(4) NOT NULL,
PRIMARY KEY (t3_name, t4_pk2),
FOREIGN KEY(t3_name, t4_pk2) REFERENCES t4 (t3_name, t4_pk2)
);
CREATE TABLE t6 (
t2_id BIGINT NOT NULL,
t1_id BIGINT NOT NULL,
t6_val BOOLEAN NOT NULL,
PRIMARY KEY (t2_id, t1_id),
FOREIGN KEY(t2_id) REFERENCES t2 (t2_id),
FOREIGN KEY(t1_id) REFERENCES t1 (t1_id)
);
CREATE INDEX idx_t2_1 ON t2 (t1_id, t2_id);
CREATE INDEX ix_t1_created ON t1 (created);
CREATE INDEX ix_t2_t1_id ON t2 (t1_id);
Expand Down
7 changes: 6 additions & 1 deletion tests/sql_db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def _meta(dir_path):
t4_pk2="str 4 primary_key",
foreign=((("t3_name", "t4_pk2"), ("t4.t3_name", "t4.t4_pk2")),),
),
t6=PKDict(
t2_id="primary_id primary_key",
t1_id="primary_id primary_key",
t6_val="bool",
),
),
)

Expand Down Expand Up @@ -124,5 +129,5 @@ def _validate_schema(meta):
else:
t.append(l)
pkunit.file_eq("schema.txt", "".join(t + sorted(i)))
pkunit.pkeq(["t1", "t2", "t3", "t4", "t5"], sorted(meta.t.keys()))
pkunit.pkeq(["t1", "t2", "t3", "t4", "t5", "t6"], sorted(meta.t.keys()))
pkunit.pkeq(meta.t.t1, meta.table("t1"))