-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add schema support to Persistent (issue #93) #1561
base: master
Are you sure you want to change the base?
Conversation
Add new `entitySchema` field and refactor callsites of `entityDB` to use `getEntityDBName` instead
[INT-844] prepend schema to entity db name
…ntityDBName revert change to `getEntityDBName`
…tters-for-entitySchema add setters and getters for `entitySchema`
…b.com:curranosaurus/persistent into curran/update-entitySchema-to-its-own-newtype
…o-its-own-newtype Create newtype for schema name
…t-schema update sqlQQ test to consider a case with a schema
…s-migrations Use new entitySchema field for Postgres migrations
…sql-queries Start using table schema in queries with Postgres
Co-authored-by: Matt Parsons <[email protected]>
Co-authored-by: Matt Parsons <[email protected]>
Co-authored-by: Matt Parsons <[email protected]>
Alright, I think I made it through all of your requests, @parsonsmatt. This should be ready for another round of review. Thanks for your advice!
Yeah, I suspect you're right that people will want to apply this feature to those backends. But I don't know what namespacing conventions people will expect for those data stores. So I agree that we should leave that decision to a future contributor. |
Looks like the MySQL schema setup failed:
I am guessing it's because the |
.github/workflows/haskell.yml
Outdated
@@ -68,6 +68,10 @@ jobs: | |||
cabal-version: ${{ matrix.cabal }} | |||
- name: Check MySQL connection | |||
run: mysql -utest -ptest -h127.0.0.1 --port=33306 test -e "SELECT 1;" | |||
- name: Create 'foo' schema in MySQL | |||
run: mysql -uroot -ptest -h127.0.0.1 --port=33306 test -e "CREATE DATABASE foo; GRANT ALL ON foo.* to 'test'@'localhost';" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think -uroot -ptest
will work because near the top of this file there's a declaration MYSQL_ROOT_PASSWORD: test
.
Maybe the host isn't called |
My current theory is that the user |
Addresses #93 by adding schema support to Persistent. You specify a Persistent model's schema using syntax like
schema=foo
.I worked on this together with @benjonesy.
Design challenges and decisions
"Schema" means many things to many backends
In this PR, we use the word "schema" to refer to various devices that backends offer for namespacing tables.
Schemas may or may not exist
We considered designing this PR so that Persistent would create schemas for the user if they did not already exist. But we chose not to do that. This means that local development with Persistent using schemas will require some manual SQL migrations to create the schemas that the user wants. But for conventional use-cases, schema creation will be a rare event, so this is not very onerous for developers. Below are some issues one would have to solve to make Persistent automate schema creation for the developer:
Three-stage migrations
RIght now, the
CREATe TABLE
DDL statements are sorted to the top of the migration output, so that the (potentially recursive) foreign-key constraints are created only after all of the tables they reference exist. If we also wanted Persistent to ensure the existence of schemas, we would need to sort backend-appropriate versions ofCREATE SCHEMA
statements above theCREATe TABLE
statements.Granting permissions in MySQL
Before a connection can use a newly created database in MySQL, one must run a
GRANT
statement to give the current user the requisite DDL operations to runCREATe TABLE
statements. We would somehow need to make Persistent aware of theGRANT
statement required.File name and directory in SQLite
SQLite's invocation for creating a new database also specifies the file name and location for that database's
.db
file. Persistent would need to be opinionated about this directory scheme, or we would have to add a configuration option, if we wanted to support schema creation in SQLite.PR Template checklist
Before submitting your PR, check that you've:
@since
declarations to the Haddockstylish-haskell
on any changed files..editorconfig
file for details)After submitting your PR:
(unreleased)
on the Changelog