Repository navigation
all: remove views - #15
Merged
Merged
Conversation
A view was declared like an entity and generated like a read-only one, and nothing put it in the database (#3). migrate.Tables held no view: only the `ent schema` command reached Graph.Views, and it printed the DDL rather than applying it. Ent inspects tables only, so a view in the desired state would have read as missing on every run. And the bundled Atlas plans no view changes at all: v1.3.0 has a schema.View type, but no driver inspects one or plans adding, changing or dropping one, so the diff half could not be wired whatever this repository did. What was left was a definition, entsql.View, that only `ent schema` ever read and that had already drifted -- a wrong table name and a wrong column count -- with nothing to say so. Nothing in this stack declares a view; protoc-gen-orm-ent and the generators beside it never have. So views go, as Gremlin did: - ent.View and ent.Viewer; load.Schema.View. - gen: Type.IsView, Graph.Views, Graph.MutableNodes (every node is mutable now, so templates range Nodes), and the notView conditions that kept create/update/delete/mutation from a view. - The IsView branches in the client, ent, entql and privacy templates. - entsql.View, entsql.ViewFor, Annotation.ViewAs/ViewFor, and the annotation's err, which only ViewFor set. - schema.NewView, Table.View, the view half of Atlas.realm, and the CREATE VIEW schema.DDL appended. - CleanUser in entc/integration/multischema, and doc/md/schema-view.mdx. sql.CreateView stays: it is the SQL builder's, and says nothing about what ent generates. TestDDL's pets table had expected owner_id twice. That was the view beside it: `append(pets.Columns[:2], pets.Columns[3])` wrote over the fur_color column through the shared slice. Without the view, pets has the columns it declares, and the expectations say fur_color. UPSTREAM.md lists views under Removed, with what to do with an upstream change that adds an IsView branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3.
A view could be declared like an entity and was generated as a read-only one, but nothing ever created it in the database. Wiring it up was not possible either:
migrate.Tablesheld no view. Only theent schemacommand reachedGraph.Views, and it printed the DDL instead of applying it.schema.Viewtype, but none of its open-source drivers inspect views or plan adding, changing or dropping them. So the diff half could not be wired, whatever this repository did.What remained was the
entsql.Viewdefinition. Onlyent schemaever read it, and it had already drifted (wrong table name, wrong column count) without anything noticing. Nothing in this stack declares a view: I searched every cached version ofprotoc-gen-orm-ent,-go,-service,protobuf-ormandprotobuf-merge.Removed
ent.View,ent.Viewer, andload.Schema.View.gen:Type.IsView,Graph.ViewsandGraph.MutableNodes. Every node is mutable now, so templates range overNodes.notViewconditions on the create, update, delete and mutation templates.IsViewbranches in the client, ent, entql and privacy templates.entsql.View,entsql.ViewForandAnnotation.ViewAs/ViewFor. The annotation'serrfield andErr()also go, because onlyViewForever set the error.schema.NewView,Table.View, the view half ofAtlas.realm, and theCREATE VIEWthatschema.DDLappended.CleanUserinentc/integration/multischema, anddoc/md/schema-view.mdx.sql.CreateViewstays. It belongs to the general SQL builder, not to what ent generates.UPSTREAM.mdlists views under Removed, with what to do when an upstream change adds anIsViewbranch or ranges overMutableNodes.A test expectation that was wrong
TestDDLexpectedowner_idtwice inpets. The view next to it caused that:append(pets.Columns[:2], pets.Columns[3])overwrotefur_colorthrough the shared slice. Without the view,petshas the columns it declares, and the expectations now includefur_color.Tests
All of the following pass locally:
go vetandgo testin the root,examples, anddialect/sql/schema/integration.entc/integrationmatrix with-race -count=2on SQLite, MySQL 8.0 and 8.4, MariaDB 10.11 and 11.4, and PostgreSQL 14 and 17..github/lint.sh.🤖 Generated with Claude Code