db-migrate / node-db-migrate

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

How to set precision and scale for decimal data type #671

Closed bahung1221 closed 4 years ago

bahung1221 commented 4 years ago

I'm submitting a...

Current behavior

I can't add precision and scale options to decimal data type. (it always use decimal(10,0))

Expected behavior

It should be able to specific precision and scale when i use below config:

price: { type: 'decimal', length: '16,4' },

db-migrate version: latest plugins with versions: latest db-migrate driver with versions: mysql latest

Additional information:

Thank you very much for a nice job! 😄

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

andrescuco commented 4 years ago

+1

patebry commented 2 years ago

If you use this it works. { type: "decimal(10,2)" }

michael-caraiani commented 2 years ago

yup { type: "decimal(10,2)" } seems to work 👍 but it's generating warnings image

so I'm still confused, what would be the correct way to add precision/scale to a decimal ? 🤔

wzrdtales commented 2 years ago

this has not been carried to every driver, but is certainly something that should.

https://github.com/db-migrate/mysql/blob/d2fdff16239c455a5ef02699a0cabf1cca5d4215/index.js#L78-L81

for MySQL you could use { type: 'decimal', precision: x, scale: x }, that would need to be added to the base driver to work everywhere though.