Skip to content

Commit 911762d

Browse files
authored
fix: Add AddCqIDs helper function (#1065)
1 parent 646d451 commit 911762d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

schema/table.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ var (
9494
reValidColumnName = regexp.MustCompile(`^[a-z_][a-z\d_]*$`)
9595
)
9696

97+
// AddCqIds adds the cq_id and cq_parent_id columns to the table and all its relations
98+
// set cq_id as primary key if no other primary keys
99+
func AddCqIDs(table *Table) {
100+
havePks := len(table.PrimaryKeys()) > 0
101+
cqIDColumn := CqIDColumn
102+
if !havePks {
103+
cqIDColumn.PrimaryKey = true
104+
}
105+
table.Columns = append(
106+
ColumnList{
107+
cqIDColumn,
108+
CqParentIDColumn,
109+
},
110+
table.Columns...,
111+
)
112+
for _, rel := range table.Relations {
113+
AddCqIDs(rel)
114+
}
115+
}
116+
97117
func NewTablesFromArrowSchemas(schemas []*arrow.Schema) (Tables, error) {
98118
tables := make(Tables, len(schemas))
99119
for i, schema := range schemas {

0 commit comments

Comments
 (0)