singlestoredb-laravel-driver icon indicating copy to clipboard operation
singlestoredb-laravel-driver copied to clipboard

Add support for the "change"-function

Open 4ice opened this issue 2 years ago • 6 comments

It would be great if this feature was supported.

As I understand, the following would have to be done in order to change a field (This example changes a field called "name" from a varchar to text):

  1. Add a column of the desired type (ALTER TABLE table_name ADD COLUMN field2 TEXT CHARACTER SET utf8mb4 DEFAULT NULL COLLATE utf8mb4_unicode_ci; )
  2. Fill values in this column with the column you want to change the data type (UPDATE table_name SET name2 = name;)
  3. Remove the previous column (ALTER TABLE table_name DROP COLUMN name;)
  4. Change the name of the new column (ALTER TABLE table_name CHANGE name2 name;)

Would it be possible to implement this? Or is there already another way to do this?

4ice avatar Oct 21 '22 19:10 4ice

Does Laravel have a change function already that works with other database backends or are you just suggesting that this pattern should be made into a nice function?

carlsverre avatar Oct 25 '22 19:10 carlsverre

@carlsverre Yes, the function exists and works with other databases. I am migrating from mysql driver to singlestore, and I have several migrations that use the change()-function that I am working on rewriting as we speak.

4ice avatar Oct 26 '22 07:10 4ice

Gotcha. This is a great feature request. Thank you!

carlsverre avatar Oct 26 '22 21:10 carlsverre

Hi, any news about this issue/feature request?

sneycampos avatar Dec 04 '22 00:12 sneycampos

@carlsverre I like this suggestion. Can this all be done in a single SQL DB transaction?

JackEllis avatar Dec 11 '22 07:12 JackEllis

Unfortunately alter tables in SingleStore don't operate within user defined transactions. So it's not possible to perform this entire column change process atomically.

carlsverre avatar Dec 12 '22 18:12 carlsverre

Is this issue still relevant? It's easy to implement this using the OP's workaround: adding, inserting, dropping, renaming.

hafezdivandari avatar Jul 13 '24 12:07 hafezdivandari

You may check PR #88

hafezdivandari avatar Jul 14 '24 07:07 hafezdivandari