https://supertokens.com/ logo
#support-questions
Title
# support-questions
s

segidev

07/15/2022, 11:14 AM
Hey there, is there a way to let supertokens use int / bigint instead of uuid as the primary key for the email_passwords table (and probably all other)? Like
user_id
would be 1 instead of "uq814uq-81412...."
r

rp

07/15/2022, 11:16 AM
Hey! You can’t change the userId type. But what you can do is to map the userId we give with her a custom userId in your own db.
Checkout the migration guide, and in there, there will be a user ID mapping section.
s

segidev

07/15/2022, 11:29 AM
Mhmm okay thanks. I saw it in the docs
Well does not exactly cover what i need
I would require to have a another type being created by SuperTokens
But it's okay i will find another way to handle it 👍
r

rp

07/15/2022, 11:30 AM
What’s the reason for having it as an int?
s

segidev

07/15/2022, 11:31 AM
Just a requirement for the project
r

rp

07/15/2022, 11:34 AM
Hmm. With the user I’d mapping feature, it would be like the user ids issued by supertokens are ints. But up to you 🙂
s

segidev

07/15/2022, 11:37 AM
The thing is i am using another ORM to link to this unmanaged table. I can't simply say the type is int when it is uuid or i'll get runtime problems
r

rp

07/15/2022, 11:39 AM
You can store a mapping of int to UUID in your db, and then override the functions we have to fetch int given the uuid, and return that. That way, to your app, the user ids will be ints
s

segidev

07/15/2022, 11:42 AM
That would be another table then having this mapping?
r

rp

07/15/2022, 11:42 AM
Yes.
We are also going to release this feature in 2-3 weeks time where we store the mapping as well
s

segidev

07/15/2022, 11:43 AM
The thing is i just need to represent what is given by email_passwords table towards my ORM system. So when i reference user.id it is the UUID und recognizes the correct type. So I define it like that:
Copy code
go
func (User) Fields() []ent.Field {
    return []ent.Field{
        field.String("id").
            Unique().
            GoType(uuid.New()).
            Immutable().
            StorageKey("user_id"),
        field.String("email").Unique().Immutable(),
        field.String("password_hash").Unique().Sensitive().Immutable(),
        field.Int("time_joined").Immutable(),
    }
}
r

rp

07/15/2022, 11:44 AM
Oh right. I see.
s

segidev

07/15/2022, 11:44 AM
And defining the table:
Copy code
go
func (User) Annotations() []schema.Annotation {
    return []schema.Annotation{
        entsql.Annotation{Table: "emailpassword_users"},
    }
}
It will be a bit tricky to link the mapping table but also the original one
r

rp

07/15/2022, 11:47 AM
So ur mapping to the orm from the db directly?
s

segidev

07/15/2022, 12:17 PM
yes
It is to maintain autocomplete and reference
r

rp

07/15/2022, 12:18 PM
Ah I see. Then I’m afraid there isn’t a straightforward way
s

segidev

07/15/2022, 12:18 PM
the ORM does not do anything though for this table
r

rp

07/15/2022, 12:18 PM
Hmm ok
s

segidev

07/15/2022, 12:20 PM
No worries, it's not a big issue 🙂