Prisma ^2.0 can't handle database creation and table creation? - database

When I tried other ORM systems(Laravel's ORM), I used the ORM system to give me direct control over the database server, such as the creation and deletion of the database and the deletion of tables.
I wonder if Prisma doesn't offer that kind of function. Does Prisma offer these functions?
I looked up the official document but I couldn't find it. Is it because of SQL injection that doesn't provide this function?

Prisma does offer this functionality via Prisma Migrate.
In short:
Prisma Client lets you send database queries at runtime of your application to read and write data in your database.
Prisma Migrate lets you manage your database schema (e.g. creating, modifying and deleting tables)
You can follow this guide to learn how to get started with Prisma Migrate: https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch-prisma-migrate-typescript-postgres

Related

Automate dropping a database and creating tables

I made a Spotify app that analyzes user data and manages interactive features by writing the API responses to a PostgreSQL database. The developer rules state that basically I have to delete the data when the user is not actively using my app.
Is there a way to automate this on the server (I'm using AWS Lightsail/Ubuntu) to do it daily? Would I need to add a datetime column to all of my tables and follow one of these: https://www.the-art-of-web.com/sql/trigger-delete-old/? Or is there a better way?

How can I do an in-memory SQL Server for integration testing?

I want to be able to create a database and tables the same way Amazon's DynamoDb client does it but with Sql Server. Is that possible?
I'm using .net Core and this is for integration tests. Figured I can throw in the code in the fixture.
Anyone have any ideas?
EF Core Migrations:
"The migrations feature in EF Core provides a way to incrementally
update the database schema to keep it in sync with the application's
data model while preserving existing data in the database."
Create and Drop APIs:
"The EnsureCreated and EnsureDeleted methods provide a lightweight
alternative to Migrations for managing the database schema. These
methods are useful in scenarios when the data is transient and can be
dropped when the schema changes. For example during prototyping, in
tests, or for local caches."
to create your tables at runtime.
And then use one of the Data Seeding techniques:
Data seeding is the process of populating a database with an initial
set of data. There are several ways this can be accomplished in EF
Core:
Model seed data
Manual migration customization
Custom initialization logic
to populate them with known data.
You could start the SQL Server (at least the logfiles) on a RAM disk. and/or use delayed durability ALTER DATABASE x SET DELAYED_DURABILITY = forced. You could also use memory optimized tables but I think you won’t get full compatibility.
BTW: it is dangerous to use such shortcuts if your development process relies entirely on it since developers very late get feedback on bad habits and performance problems.
For that kind of volatile databases (also applies to containers) you need to add some code to your test pipeline or product tomactually create and populate the DB. (If you use containers you can think about packaging a pre-populated DB snapshot)

Connect with more than two databases using Django ORM, one database is legacy database without migrate into app

We want to connect a remote existing database from settings.py, can we use those tables directly using model without migrate from app.
We know about the legacy database connection but inspect.db command always asks to migrate the connected database.
Is using mysql connector is preferable or it is out of standard, please suggest.
Thanks, your help is appreciated!
I think what you are looking for is the managed meta option in your models. When you define your models, by default you have managed=True. If you want to use an existing database without Django interfering with migrations, you should use managed=False.
See this part of the doc:
[...] If False, no database table creation or deletion operations will be performed for this model. This is useful if the model represents an existing table or a database view that has been created by some other means. This is the only difference when managed=False. All other aspects of model handling are exactly the same as normal. [...]

Sails DB tables to models export

I was wondering if there is any way to export the DB tables to Sails Models structure, so i can make a instant replica of a current DB in sails and start using the DB with sails.
Its kinds of reverse migration. (DB -> SAILS)
Yes as of only just a couple of weeks now a module has been created to do this for you. At present it is limited to only a couple of database types e.g. postgresql and mySql however the publisher seems to be actively working on new database conversions also.
To find all the info check here:
https://www.npmjs.com/package/sails-inverse-model
I have used it to convert 53 postgresql tables to sails models.

ASP.NET MVC Code-First EF - Possible to use EF without database create permissions?

So I'm working on an ASP.NET project for university. We have to upload our code to a server running IIS and SQL Server 2008. I've written my project using MVC Code-First EF. I understand that the Entity Framework system needs permission to create the database to work properly (you can't just give it an empty database and let it fill it with data). This has created a problem for me since I do not have database creation privileges on the shared SQL Server. Is there any way around this?
As you don't have permissions, it sounds like you'd need to get a DBA to create your database on the server you are trying to deploy to - this could be done from either a database creation script or from a database backup of the db on your dev machine. You can then instruct EF code first not to try to create / update the database automatically by adding this line to your global.asax (or indeed anywhere before you first access the database)
Database.SetInitializer<YourContextType>(null);
You can use an existing database, rather than let EF create one for you. I have done this myself, but admittedly only when using EF Migrations. Otherwise, you run into trouble with missing table exceptions and what not.
When using migrations, just point your connection string to your empty database, create an initial migration to populate the database with your schema and then update the database itself.
See this answer: How do I create a migration for an existing database in EntityFramework 4.3?
.. which include this nice link to getting started with EF Migrations: http://thedatafarm.com/blog/data-access/using-ef-migrations-with-an-existing-database/
All this is available through Nuget, and if you have access to Pluralsight content, I can highly recommend Julie Lerman's video on the topic.
If you don't want to use Migrations, you can still use Code First if you just create the database objects manually using SMMS, but obviously you have the manual work of keeping your model and the database in sync.

Resources