Skip to content
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

fix: insert on uuid with default value #911

Merged
merged 3 commits into from
Nov 25, 2024
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 db-service/lib/fill-in-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const generateUUIDandPropagateKeys = (entity, data, event) => {
if (event === 'CREATE') {
const keys = entity.keys
for (const k in keys)
if (keys[k].isUUID && !data[k] && !assoc4(keys[k])) //> skip key assocs, and foreign keys thereof
if (keys[k].isUUID && !data[k] && !assoc4(keys[k]) && !keys[k].default) //> skip key assocs, and foreign keys thereof
data[k] = cds.utils.uuid()
}
for (const each in entity.elements) {
Expand Down
2 changes: 1 addition & 1 deletion test/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ entity C : managed {
toB : Composition of many B
on toB.ID = $self.B;
};
entity BooksAnnotated as projection on Books;
entity BooksAnnotated as projection on Books;
1 change: 1 addition & 0 deletions test/compliance/resources/db/basic/common.cds
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ entity temporal : _cuid, _temporal {}

// Set default values for all literals from ./literals.cds
entity ![default] : _cuid {
uuidDflt : UUID default '00000000-0000-0000-4000-000000000000';
bool : Boolean default false;
integer8 : UInt8 default 8;
integer16 : Int16 default 9;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const dstring = size => ({ d: 'default'.slice(0, size), o: 'not default'.slice(0, size) })

const columns = {
uuidDflt: { d: '00000000-0000-0000-4000-000000000000', o: '11111111-1111-1111-4111-111111111111'},
bool: { d: false, o: true },
integer8: { d: 8, o: 18 },
integer16: { d: 9, o: 19 },
Expand Down
1 change: 0 additions & 1 deletion test/scenarios/bookshop/insert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ describe('Bookshop - Insert', () => {
expect(written.price).to.be.eq(entry.price)
}
})

})