I have around 20 data models and all these models needs createdAt and updatedAt fields. Is there anyway to add these fields automatically for existing and future models when I run prisma migrate command.
It's not currently possible to automatically add a createdAt and updatedAt field automatically to all the models.
If you can create a Feature Request explaining your use case, prisma's engineering and product team can have a look and can prioritise it if other people also require the functionality.
Related
I'm using Prisma ORM with GraphQL.
I've got a user type, and for obvious reasons, I don't want the password field able to be queried. Is there any way to do this, either in Prisma, or GraphQL (or PostgreSQL)?
Currently you can use select to fetch the fields that you require and omit the ones that need to be private.
There's a request here for the same that will allow to exclude specific fields.
There's a collection with 100.000 documents. Only 10 of them must have additional property that is not necessary for other documents (e.g. list of departments with only top ones have property 'Location');
As far as I understand both approaches should work just fine, but which one is preferable since using noSql db:
add one more collection with documents that have 2 property: DepartmentId, Location.
add property 'Location' to only selected documents, so others won't have it.
The problem you are facing is well known. You have the same with source code for example.
When you are updating a piece of code, do you save it as User.js, User2.js, User3.js ... ?
Or do you use a versionning system like git and have an unique User.js?
Translating the git analogy to your issue, you should update the current data.
In mongodb you actually have two choice to perform the update.
Update the model in your code, and update every entry in database to match the new model.
Create a new model that will apply to new entries, and still have the old model to handle old formatted data.
use-more-than-one-schema-per-collection-on-mongodb
I have been trying to get my head wrapped around MongoDB, as it's used by Spring, so I decided to start a little project in Spring Roo.
In my project, I am storing my User Login data to MongoDB. The trouble is that the registration process, which creates a new User object and stores it in the MongoDB, has a tendency to create duplicates despite the fact I have #Unique on the loginId field.
Now, I know part of the problem is that I am thinking about things from a JPA/RDBMS perspective, and MongoDB is not a relational DB and thus has a different set of parameters in which to operate with, but I having trouble finding guidance in anything more than a VERY simple sample code.
First, what Spring/Other annotations are available, and more importantly, commonly used when dealing with MongoDB from a Spring-world? Second, when dealing with documents that need to be "uniqued", how does one typically do this? Do you first search on the unique field to ensure it's not already there first, then do the insert? Third, in JPA-land, I could use the annotations #PrePersist and #PreUpdate to do last-minute data manipulation, like MD5-hashing passwords that have been updated or adding/updating a "Last Modified" date just prior to storing. I know this are JPA-isms, but can I still use those, and if not, is there an alternative for use with Spring Data/MongoDB?
I ended up using the #Id annotation on my Entities, which indicates which field is used as the id field. As long as the field is unique, writting subsequent updates will properly replace the existing entity instead of adding a new one.
I ended up creating additional method to check if there exists a data which have a duplicate value to the one we are entering.
If it exists, i return failure mentioning that there exist duplicate value. Otherwise it saves the newly entered value
I'm building my EF (v4.0.30319) data model from my SQL Server database. Each table has Created and Updated fields populated via database triggers.
This database is the backend of a ASP.NET Web API application and I recently discovered a problem. The problem is, since the Created and Updated fields are not populated in the model passed into the api endpoint, they are written to the database as NULL. This overwrites any values already in the database for those properties.
I discovered I can edit the EF data model and just delete those two columns from the entity. It works and the datetimes are not overwritten with NULL. But this leads to another, less serious but more annoying, problem... my data model has a bunch of tables that contain these properties and all the tables need to be updated by removing these two columns.
Is there a way to tell EF to ignore certain columns in entities across the entire data model without manually deleting them?
As far as I know, no. Generating the model from the database is going to always create all of the fields from the database table. Well, as long as it has a primary key it will.
It is possible to only update the fields that you want i.e. don't include the "Created" and "Updated" fields in your create and update methods. I'd have to say though, that I'd think it'd be better if those fields didn't even exist on the model at that point. You may at one point see those fields on the model and not remember that they won't get persisted to the DB.
You may want to look into just inserting the datetimes into those fields when you call your create() and update() methods. Then you could just ditch the triggers. You'd obviously want to use a class library for all of your database operations so this functionality would be in one place. To keep it nice and neat, you know?
So I'm having a problem modeling this in Mongo/Mongoid:
Teams can participate in an event and each event will have results for each team (score, actions leading the the score, etc.)
Basically I want to display a scoreboard of sorts for the event.
So here is what I have:
Event
has_and_belongs_to_many :teams
Team
field :name
field :color
has_and_belongs_to_many :events
This works fine but I need to know how to model the relationship between each team and the event.
TeamEventStats (probably not the best name)
field :score, :type => Integer
# etc. etc.
In ActiveRecord/RDBMS I could do a through (join) model and go on my merry way but
I don't know how to do this in Mongo.
Anyone know a good way of doing this or a better way of modeling the relationship?
this may help u out. http://mongoid.org/docs/relations/referenced/n-n.html
A has many through is really just a couple many-to-one's to create a many-to-many, with the added bonus that you can store relationship data in addition to the foreign keys (like your team stats). So you can easily accomplish this in Mongoid using something like:
Event
has many :team_stats
Team
has many :team_stats
TeamStat
belongs_to :events
belongs_to :team
field :score, :type => Integer
There's nothing hierarchical about this though. If you need to be able to query both (give me the stats for all team for Event A, also give me the stats for all events for Team #1) then it's primarily a relational schema. Know what I mean? So unless you have a lot of other hierarchical / document based data in the app, I'd probably go with an RDBMS.
However, if you only ever needed to query stats by the event then you could make this more document friendly by embedding team stats within each event instead of associating Events and Team via another collection.
By the same logic, if you only ever needed to query stats by the team then you could embed event stats within each team.