fizz icon indicating copy to clipboard operation
fizz copied to clipboard

Housekeeping, implement better SQLite DDL, resolve pesky bugs

Open aeneasr opened this issue 4 years ago • 4 comments

~This PR adds support for DROP COLUMN without the temp table dance as DROP COLUMN is now officially supported in SQLite 🎉 ~ I had to revert this due to implicit implications on foreign keys and indices :/

It also resolves the notorious "null": false issue.

Additionally, this patch adds new functionality to add_column, allowing to define a foreign key when creating a column. This works for all databases and adds support for introducing foreign keys to SQLite schemas after a table has been created (not possible previously):

	ddl := `ALTER TABLE "users" ADD COLUMN "mycolumn" TEXT NOT NULL DEFAULT 'foo' CONSTRAINT projects_subscription_id_fk REFERENCES subscriptions (id, kid) ON DELETE RESTRICT ON UPDATE NO ACTION;`
	schema.schema["users"] = &fizz.Table{}

	res, _ := fizz.AString(`add_column("users", "mycolumn", "string", {"default": "foo", "size": 50, "foreign_key": {
  "table": "subscriptions",
  "columns": ["id", "kid"],
  "name": "projects_subscription_id_fk",
  "on_delete": "RESTRICT",
  "on_update": "NO ACTION"
}})`, sqt)

This PR also upgrade PostgreSQL and CockroachDB and MySQL to supported versions as the versions used previously were no longer maintained.

I have updated all the tests and integration tests also. Yay!

Closes #110 Closes #62

aeneasr avatar Dec 02 '21 18:12 aeneasr

Sorry, this PR grew in scope rather quickly. I resolved many bugs though in MySQL and SQLite...

aeneasr avatar Dec 03 '21 10:12 aeneasr

I found another bug in SQLite where the internal meta schema was not appropriately updated on rename_column. During review, I think you can ignore the test stubs and just focus on *.go files :)

aeneasr avatar Dec 03 '21 17:12 aeneasr

And another one, this time it's rename_table, also not correctly updating the meta schema representation.

aeneasr avatar Dec 03 '21 18:12 aeneasr

Oh! @aeneasr, do you still working on this PR? I am currently cleaning up all sub-modules for buffalo and just want to know if you are still working on it.

sio4 avatar Sep 15 '22 12:09 sio4

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment. Otherwise, this will be closed in 7 days.

github-actions[bot] avatar Oct 31 '22 03:10 github-actions[bot]

This PR was closed because it has been stalled for 45+7 days with no activity.

github-actions[bot] avatar Nov 08 '22 03:11 github-actions[bot]