https://www.ory.sh/ logo
#contributors
Title
# contributors
e

early-fountain-60696

04/13/2022, 7:54 AM
Hi all, I've almost finished implementing SAML in Kratos, but I have a small question. When creating the database, there are 5 lines in identity_crendentials_types.
kratos=# select * from identity_credential_types;
id                  |     name
78c1b41d-8341-4507-aa60-aff1d4369670 | password
6fa5e2e0-bfce-4631-b62b-cf2b0252b289 | oidc
5e29b036-aa47-457f-9fe6-aa8b854a752b | totp
567a0730-7f48-4dd7-a13d-df87a51c245f | lookup_secret
6b213fa0-e6ad-46cb-8878-b088d2ce2e3c | webauthn
I would like to add a new line for SAML. I know it's all in the migration scripts but there are a lot of them and I don't really understand how it works. Could someone explain to me how to add my SAML line automatically when the DB is created?
s

steep-lamp-91158

04/13/2022, 8:44 AM
here we have all migration files: https://github.com/ory/kratos/tree/master/persistence/sql/migrations/templates you just have to add one more they are basically named by the current date and time, just stick to that pattern to make it the newest migration your migration will probably be very similar to https://github.com/ory/kratos/blob/1fbabc24c6ab461e1bea8039ae171a585c4d43c5/persis[…]ns/templates/20220301102701_identity_credentials_version.up.sql
2
and also add a down migration that reverts your change
1
to then "render" the proper migrations, run
make migrations-render-replace
1
after all of that worked, you will have to add a testdata file https://github.com/ory/kratos/tree/master/persistence/sql/migratest and also add assertions
1
e

early-fountain-60696

04/13/2022, 8:49 AM
Ahh this is perfect, thank you for this complete explanation! @User
s

steep-lamp-91158

04/13/2022, 8:54 AM
np, we should probably document this a bit better @User I am sure you want to do that 😉
m

magnificent-energy-493

04/13/2022, 9:21 AM
Puh 😅 I can take this information and add it to the contributing docs e.g. ### SQL migrations in Ory Kratos ?
s

steep-lamp-91158

04/13/2022, 9:21 AM
In any project, maybe add a readme in the migrations directory?
m

magnificent-energy-493

04/13/2022, 9:25 AM
It is the same for every project?
s

steep-lamp-91158

04/13/2022, 9:25 AM
yes
🙏 1
f

faint-sandwich-26722

04/13/2022, 9:29 AM
@User Hey, thanks very much for your answers 🙂 I'm working with @User Should we commit all the generated SQL scripts in persistence/sql/migrations/sql as well? Why isn’t this part in the .gitignore btw?
s

steep-lamp-91158

04/13/2022, 9:32 AM
yes they should be committed, because we use(ed) https://github.com/gobuffalo/fizz/ the migrations have to stay the same, even if that tool ever changes but we are actually now moving away from that for various reasons
1
so in case you have a bug in fizz that gets fixed, new instances of kratos would have a different (although correct) schema than older once that makes it virtually impossible to later fix all of them
1
f

faint-sandwich-26722

04/13/2022, 9:35 AM
It's very clear, thank you!
Hey, I did a rebase today, and I run into the error
unable to fetch records: ERROR: column identities.metadata_admin does not exist (SQLSTATE 42703)"
reaching the api /admin/identities So I tried to do a
kratos migrate
but then I run into the error
An error occurred while connecting to SQL: error executing migrations/sql/20220301102702000001_identity_address_performance.postgres.up.sql, sql: UPDATE identity_verification_addresses SET value = LOWER(value) WHERE TRUE;: ERROR: relation "identity_verification_addresses" does not exist (SQLSTATE 42P01)
So I though I'd need to do a
make migrations-render-replace
, but it seems to no longer exist. What should I do to migrate properly my database?
s

steep-lamp-91158

08/05/2022, 3:04 PM
hm migrate should be all that's needed
why not start with a new database?
or is it not just a dev setup?
f

faint-sandwich-26722

08/05/2022, 3:11 PM
Okay good to know We had to modify a bit the database so I wanted to migrate directly rather than to restart from a new one, but I'll try then I'll let you know, thanks 🙂
Hey, we solved the problem. It was due to leftover migration files that weren't up to date, everything works fine now 🙂
m

magnificent-energy-493

08/09/2022, 9:53 AM
Hey thanks for following up Seb 🙂 glad it got resolved.
12 Views