db-migrate / node-db-migrate

Database migration framework for node
Other
2.32k stars 360 forks source link

Add explicit support for UUIDs #532

Open LandonSchropp opened 6 years ago

LandonSchropp commented 6 years ago

I'm submitting a...


[ ] Bug report  
[x] Feature request

Current behavior

When I add a column with a type of uuid, I get the following warning:

[WARN] Using unknown data type UUID

Expected behavior

I would expect no warning message as long as I have the pgcrypto extension installed.

Minimal reproduction of the problem with instructions

Add a column with a type of uuid.

What is the motivation / use case for changing the behavior?

Personally, I'm a fan of having no warnings in my project. I believe when warnings start piling up that aren't problems, developers begin to ignore them, which causes real issues to be missed. In this case, the uuid type is valid, but db-migrate doesn't recognize it.

Environment

db-migrate version: 0.10.2
db-migrate-pg: 0.2.5
db-migrate-plugin-babel: 1.0.0

Additional information:
- Node version: 9.2
- Platform: Linux (via Docker)

Others:

I believe this issue originally surfaced in #34. I do think allowing pass-through column info is a good idea, but I don't feel like UUIDs should produce warnings.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/53444905-add-explicit-support-for-uuids?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F73887&utm_medium=issues&utm_source=github).
ezy commented 5 years ago

Postgres requires the "uuid-ossp" extension for this. For anyone who requires it, create a migration with the following:

exports.up = (pgm) => { pgm.createExtension('uuid-ossp') };
exports.down = (pgm) => { pgm.dropExtension('uuid-ossp') };

and from there you can use uuid for id's with a default as follows:

id: { type: 'uuid', primaryKey: true, default: pgm.func('uuid_generate_v4()') },

Hope this helps someone.

wzrdtales commented 5 years ago

This is a driver issue though. Feel free to add it to the pg driver. Quick lookup showed for me it is not one of the non supported features, so it can be definitely added to the mapping.

cawel commented 5 years ago

Sadly, @ezy's solution did not work for me. Even with that "uuid-ossp" extension installed, just using 'uuid' as a type for one of my db columns (without using a function for the default value), I still get the warning:

[WARN] Using unknown data type UUID
IhsanMujdeci commented 4 years ago

What worked for me is id: { type: 'uuid', primaryKey: true, default: new String('(UUID())') }, This is for mysql