Prisma migration cause data lose - javascript

I'm new to prisma I'm working on a project with nodejs & prisma , my database isn't empty and I did some changes in prisma schema and I want to migrate it without data lose is there any solution please ?

Answered based on the problem you mentioned in the comment: "I want to add some columns but I don't want existing data be lost"
if you want to add new columns to an existing database without causing data loss you need to make sure the new columns/field are optional. This can be done in Prisma by marking the type of the field with a ?.
If you need the field to be mandatory, you could do it in three steps:
Create the new field as optional first in your prisma schema and run a migration
Run a script to update all records with that field to have certain data (what that data should depend on your context). This will have to be done for the production database data as well.
Mark the field is as mandatory in your Prisma schema and run a migration. It will not cause data loss now because the field is non-null for all records in the database.

Related

MEAN: Doing database queries in Angular Frontend?

I was wondering if it is somehow possible to do MongoDB No-SQL Queries (or even SQL-queries for sql database) in the Angular frontend, like formulating the query and then sending the query string to the database and getting a subset of values back (e.g. in JSON-format).
Because the problem that I currently have is, that for each data snippet that I need, I have to create a specific route (e.g for one specific graph) and then do my middleware-function for that route that queries for the data in mongodb (e.g by mongodb aggregation framework). And then finally, do a http-request in Angular frontend, eventuelly format the data in javascript in angular and then insert the data in correct format into the appropriate charting-framework (e.g ngx-charts).
E.g. If I would like to filter the data in some chart for specific fields, or do some aggregation etc. on the same chart dynamically, I probably would just query all data from beginning, and then create my own (e.g. filter or other data manipulation) functions in javascript for my chart functions.
I heard there are some ways to do this also in the backend, e.g in Node or MongoDB Aggregation framework, there exists $facet operator that can choose some path for data operation, but I actually don't know how this works together with the Frontend...
Is there not a more direct way to query just the data that I need for a specific component without setting up routing and everything else around?

Parse .md file with php or javascript

Is there a way to parse an .md file with php or javascript for code snippets.
My scenario is the following:
I have been migrating an old system (php4) to a Laravel Framework(php7) which needed Schema updates. All of this updates I made it manually( I know I could used migrations but the table structure is quite extensive and I want to persevere the old datas in my new system) and I made a history of changes over mysql updates in a Changelog.md.
Now I try to make an automised migration on schema check if matches some negative rules on table columns with a middleware. For example if Table X does not contain columns Y,Z .. than my system is obsoleted and needs an update of schema and I redirect to dedicated Controller.
no I want to read the changelog with changes let it run this mysql updates.
You can do it using http://parsedown.org/
$Parsedown = new Parsedown();
echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello<em>Parsedown</em>!</p>
You can install it for Laravel easily : https://github.com/parsedown/laravel

JsGrid - Auto Increment ID

I recently started using JsGrid and I really like it. It is simple to interact with and well documented.
I though face a small issue:
Whenever I insert a new row in the JsGrid application I get asked an ID. If this ID happens to be the same as an already existing ID, it will give my an error on my MySql database (unique key).
Is there a way to fill in the ID for the user and make sure he can not alter it while inserting?
Thanks!
Usually ID is generated on the DB level. So user should not provide the ID for new items. Remove ID field from the grid or just make it readonly, removing the type attribute.
It's implemented in the sample project, showing how to use jsGrid with PHP + MySQL RESTful backend https://github.com/tabalinas/jsgrid-php.

Listen to an event from node server js when new row is inserted to mysql table from app

I am trying to integrate socket.io + node.js + mysql . node-mysql is used to allow node.js to access the MySQL database. A table named tableA in the MySQL database updates with new data every 10 minutes.
Problem: Using node, I need the node server to continuously check tableA for changes whenever tableA gets updated(new row). What is a good way to achieve this?
I am thinking if I used setInterval(checkDb(tableA), 10*60*1000) for fetching all rows and check the changes, the checkDbquery function may not coincide with the database update.
I also happen to be using socket.io so will a good method be for the node system to emit('dbUpdated') from the node server to node client for realtime display of value.
Can anyone help me to do this?
Instead of firing query to fetch all records and then check if anything has changed, you can create a trigger on your tableA. Whenever any operation occurs like insert in your case, just save a timestamp in some other field or other table. So whenever you query after certain intervals you should query this single filed and save this time stamp. And use it to compare it with next timestamp found in query to see if anything has changed.

SpagoBI data set: use javascript to access to MongoDB data base

Since data set in SpagoBI could be created using scripts, I need to connect, query my MongoDB data base using javascript (or Groovy).
I need to use scripts to be able to execute aggregation on the mongoDB data, I can't use aggregation directly on my MongoDB because my data type is String
I dont know how to access my Database using scripts
Any ideas?
You should create a Mongo dataset. The steps to create are:
Step1: Create a Mongo datasource in the administrator console. Notes: the type must be JDBC and the value for Class input field must be "mongo"
JDBC: {unit_host}:{port}/${db}
CLASS: mongo
Step2: now you can create a dataset. The procedure is the same of the query datasets. The difference here is the language.. JS instead of SQL.
Take a look at the SpagoBI wiki in particolar here: http://wiki.spagobi.org/xwiki/bin/view/spagobi_server/data_set#HQueryDataSet28Mongo29
When connecting to mongoDB, you pass auth stuff in the url. Since the scripts lies on the client side, it would be hard to make the connection secure (unless you are talking about backend JavaScript). Anybody would be able to see how to connect to your DB and for instance delete all content.
I would suggest a simple api to interface the database. Then u control the access to what a user can do towards the database.
Or have I misunderstood the scenario?

Categories

Resources