-
Notifications
You must be signed in to change notification settings - Fork 73
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
Database deploy - Automatic schema evolution #922
Comments
Hi @federicobelotti , All the best, |
Hi @federicobelotti, I have tried it out in my local bookshop, with the following versions: ❯ cds --version
@cap-js/cds-types: 0.3.0
@cap-js/postgres: 1.8.0
@cap-js/sqlite: 1.6.0
@capire/bookshop: 1.0.0
@sap/cds: 7.9.0
@sap/cds-compiler: 4.9.0
@sap/cds-dk: 7.9.0
@sap/eslint-plugin-cds: 2.7.0
Node.js: v18.18.2 after adding postgres: ❯ npm add @cap-js/postgres
added 136 packages, and audited 138 packages in 6s
21 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
❯ cds env requires.db --production
{
impl: '@cap-js/postgres',
dialect: 'postgres',
vcap: { label: 'postgresql-db' },
schema_evolution: 'auto', -- ⬅️ this looks correct
kind: 'postgres'
} I can see that Now I connect to my local postgres instance and insert a new record: > await INSERT.into(Authors).entries({ID: 42, name: 'Stephen King'} )
InsertResult { results: [ { changes: 1 } ] }
> await SELECT.from(Authors).where('ID = 42')
[
{
ID: 42,
name: 'Stephen King',
createdAt: '2024-05-13T08:04:54.307Z',
createdBy: 'anonymous',
modifiedAt: '2024-05-13T08:04:54.307Z',
modifiedBy: 'anonymous',
dateOfBirth: null,
dateOfDeath: null,
placeOfBirth: null,
placeOfDeath: null
}
] to reproduce your scenario, I will add a new field to the after re-deployment, I execute the query from above again: > { Authors } = cds.entities
[object Function]
> await SELECT.from(Authors).where('ID = 42')
[
{
ID: 42,
age: null,
name: 'Stephen King',
createdAt: '2024-05-13T08:04:54.307Z',
createdBy: 'anonymous',
modifiedAt: '2024-05-13T08:04:54.307Z',
modifiedBy: 'anonymous',
dateOfBirth: null,
dateOfDeath: null,
placeOfBirth: null,
placeOfDeath: null
}
] on my side, everything works as expected. ❯ cds env requires.db --production
{
impl: '@cap-js/postgres',
dialect: 'postgres',
vcap: { label: 'postgresql-db' },
schema_evolution: 'auto',
kind: 'postgres'
} could you please provide a sample repository, with detailed steps to reproduce your scenario? |
Hello @patricebender,
And in the
Inside the Thank you for your clarifications, |
Hi all,
I faced a little problem while trying to take advantage of the automatic schema evolution within a PostgreSQL database (but the issue has been replicated with SQLite as well).
Months ago, whenever a change to the data model was made, while doing a
cds deploy
I could automatically have the changes reflected to the database schema without losing data without setting anything specific in the app configuration.After upgrading the CDS libraries (
cds-js
as well ascds-dk
) to the current version (7.9.X) I noticed that at each deploy, I kept losing the data since tables were dropped and created. Then I found out that thecds_model
table has never been created since the first deployement, so no schema evolution was happening at all.The documentation regarding this topic states you can have automatic schema evolution out-of-the-box and that, in order to not use it, you can disable it inside the
package.json
.I actually had to do the opposite, which was to explicitly enable it through the
"schema_evolution": "auto"
parameter set in thepackage.json
file.Checking the env data prior to enabling that setting, the
cds.requires.db.schema_evolution
variable value turned out to beundefined
.Is the documentation wrong or is the other way around and it is, in fact, a bug?
Thanks,
Federico
The text was updated successfully, but these errors were encountered: