Skip to content
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

Check for existence of entities before generating them #1255

Merged
merged 7 commits into from
Apr 27, 2021

Conversation

parsonsmatt
Copy link
Collaborator

@parsonsmatt parsonsmatt commented Apr 27, 2021

Before submitting your PR, check that you've:

  • Documented new APIs with Haddock markup
  • Added @since declarations to the Haddock
  • Ran stylish-haskell on any changed files.
  • Adhered to the code style (see the .editorconfig file for details)

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Bumped the version number if there isn't an (unreleased) on the Changelog
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

@parsonsmatt parsonsmatt changed the base branch from master to persistent-2.13 April 27, 2021 18:38
@@ -321,71 +321,86 @@ fixForeignKeysAll unEnts = map fixForeignKeys unEnts
-- the names of the referenced columns
fixForeignKey :: EntityDef -> UnboundForeignDef -> ForeignDef
fixForeignKey ent (UnboundForeignDef foreignFieldTexts parentFieldTexts fdef) =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole function should get trashed

we can't pass in the pre-existing entities here meaningfully so we shouldn't even be trying to get this right

ConstraintNameDB
. T.replace oldDbName dbname . unConstraintNameDB
$ foreignConstraintNameDBName fdef
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is all stylistic, no functionality changes

if all ((nullSetting ==) . isNull) fds
then nullSetting
else error $
"foreign key columns must all be nullable or non-nullable"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all style, no function changes

Just err ->
error err
Nothing ->
(fieldDef, ((haskellField, fieldDB fieldDef), (parentFieldHaskellName, parentFieldNameDB)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more style changes. lawd help those names were awful.

, foreignFieldCascade = FieldCascade
{ fcOnDelete = onDelete
, fcOnUpdate = onUpdate
go (constraintName:rest) onDelete onUpdate
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style again

filterM shouldGenerateCode
$ embedEntityDefs
$ map (setDefaultIdFields mps)
$ ents'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the Meat of the change

inlined the changes and did filterM to skip things already defined.

-- we can't just use 'isInstance' because TH throws an error
shouldGenerateCode :: EntityDef -> Q Bool
shouldGenerateCode ed = do
mtyp <- lookupTypeName entityName
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to use lookupTypeName instead of isInstance because lookupTypeName returns Nothing if the type name is not in scope, while isInstance merely dies with an unrecoverable compile error.

profile MBDogId

-- TODO: make the QQ not care about this table being missing
-- Foreign MBCompositePrimary bar_to_comp name age
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stupid qq

@parsonsmatt parsonsmatt merged commit 8a9b907 into persistent-2.13 Apr 27, 2021
@parsonsmatt parsonsmatt deleted the matt/mkPersist-check branch April 27, 2021 18:57
parsonsmatt added a commit that referenced this pull request May 5, 2021
* Internalize SqlBackend (#1225)

* abstractification

* abstractification

* Internalize SqlBackend

* suppor tother sql dbs

* bounds

* asdf

* import data.monoid

* limitoffset and backendspecificoverrides

* use setter

* getConnUpsertSql

* formatting

* sigh

* clean warns

* cabal formatting

* merge resolve

* lol

* ok

* update changelogs

* one more [ci skip]

* Implicit ID Column Configuration (#1234)

* Implicit ID Column COnfiguration

* PersistSettings is internal

* start teasing out the module structure

* move around, factor out the Names module

* start enumerating types, make entitydef abstract

* entity def abstraction

* teasing out the EntityDef stuff

* builds

* testinggg

* it works

* it works

* tidy up

* sigh

* i hate you

* tidy

* wrote test for mysql, need to set maxlen sigh

* mysql test, need to be able to set maxlen

* support mysql lmfao

* whyyy

* Deprecate mpsGeneric (#1250)

* discoverEntities (#1253)

* discover entities

* remove fdescribe

* changelog

* yupo

* remove error

* Fix migrations (#1252)

* Better migrations

* why is the test failing

* Columns are present in entityFields now, but the generated code is broken.

* th specs work

* fixed mkColumns

* changelog entry

* fix mongo

* no idea why this is broken now

* why on earth did this work

* remove debug trace statements

* typo

* what no put that back in

* Check for existence of entities before generating them (#1255)

* wtf

* hmmm

* refactor and tidy

* are foreign fields never right ?!

* changelog

* fix comments

* dead code

* Implement config for customising the FK name (#1244)

* Implement config for customising the FK name

* Update changelog

* Tweak test description

* Tweaks/better use of types

* Review tweaks

* Some initial post-review changes

* Table name turned out to be EntityNameHS

* Do the same thing but for the constraint

* Expose more stuff

* Some refactoring / cleanup

* Fix changelog indentation

* Tidy code layout

* QuasiQuoter Improvements (#1256)

* QQ now returns UnboundEntityDef

* Relocate fixForeignKeysAll

* deprecate some stuff, reorganize some code

* ok, now we need to set sql types appropriately.

* dodgy instances are banned

* fuse away the EntityDefSqlTypeExp stuff

* refactor to top level

* fuse sqlTypeExp in there

* fix Key vs Id stuff

* still need to get the foreign key types right

* hmmm

* move to QuasiSpec

* clean up tests

* so close

* ok but what if i don't fix foreign keys

* wip

* oh man please

* getting closer...

* make some tests

* fix json and keyFromValueM

* slightly more graceful handling

* return dummy field for id, from persist values

* got some tests passing

* well sqlite works

* pg tests running

* what happened

* hmm mongo is trashed maybe

* bye mongo

* ok for real bye mongo, for now at least

* clean warns

* asdf

* drop GHC 8.2 support

* sigh

* lots of commments

* Merge branch 'master' into persistent-2.13 (#1261)

* Reexport PersistValue

* fix json for MigrationOnly

* Export onlyOneUniqueDef (fixes #1194)

* use onlyOneUniqueDef in persistent-postgresql

Co-authored-by: Dan Brooks <danbroooks@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant