‚̧Nearsighted Penguin March
    Wondering what‚Äôs next for npm?Check out our public roadmap! ¬Ľ

    @prisma/lift
    TypeScript icon, indicating that this package has built-in type declarations

    0.3.384¬†‚Äʬ†Public¬†‚Äʬ†Published

    Prisma

    Declarative data modeling & database migrations

    Get started ‚ÄĘ Features ‚ÄĘ Docs ‚ÄĘ Workflow ‚ÄĘ Supported databases


    Prisma Migrate is a powerful database schema migration tool. It uses a declarative data modelling syntax to describe your database schema. Prisma Migrate stores your entire migration history and easily lets you revert and replay migrations. When migrating your database with Prisma Migrate, you can run provide before- and after-hooks to execute scripts, e.g. to populate the database with required values during a migration.

    It is part of the Prisma 2 ecosystem. Prisma 2 provides database tools for data access, declarative data modeling, schema migrations and visual data management. Learn more in the Prisma 2 announcement.

    Note that Prisma Migrate is currently running in Preview. The version available has severe limitations that make it unsuitable for production workloads, including missing features, limited performance and stability issues. We will address all these limitations before issuing a stable release later this year.

    Docs

    Getting started

    The easiest way to get started with Prisma Migrate is by installing the Prisma 2 CLI and running the interactive init command:

    npm install -g prisma2
    prisma2 init hello-prisma

    The interactive prompt will ask you to provide database credentials for your database. If you don't have a database yet, select SQLite and let the CLI set up a database file for you.

    Learn more about the prisma2 init flow here.

    Features

    • Declarative data modelling syntax
    • Supports relational and document databases (more coming soon)
    • Keeps a migration history
    • Before- and after hooks to run scripts for complex migrations
    • Simple defaults, optional complexity for advanced use cases
    • Revert and replay migrations
    • Works with existing databases using schema introspection
    • CLI to support all major workflows

    Docs

    You can find comprehensive documentation for Prisma Migrate in the Prisma 2 docs.

    The Prisma Migrate workflow

    1. Configure database access

    Specify the connection details for your database as a data source in your Prisma schema file. The connection details might differ per database, but most commonly you'll provide the following:

    • Host: The IP address or domain name of the machine where your database server is running.
    • Port: The port on which your database server is listening.
    • User & password: Credentials for your database server.

    Here is an example project file that connects to a local PostgreSQL database:

    // schema.prisma
     
    datasource postgres {
      url      = "postgresql://user:password@localhost:5432"
      provider = "postgres"
    }
     
    generator photonjs {
      provider = 'photonjs'
    }

    2. Define initial data model

    The data model definition is a declarative and human-readable representation of your database schema. Here is the project file from above extended with a sample data model:

    // schema.prisma
     
    datasource postgres {
      url      = "postgresql://user:password@localhost:5432"
      provider = "postgres"
    }
     
    generator photonjs {
      provider = 'photonjs'
    }
     
    model User {
      id        Int      @id
      createdAt DateTime @default(now())
      email     String   @unique
      name      String?
      role      Role     @default(USER)
      posts     Post[]
    }
     
    model Post {
      id         Int        @id
      createdAt  DateTime   @default(now())
      updatedAt  DateTime   @updatedAt
      author     User
      title      String
      published  Boolean    @default(false)
    }
     
    enum Role {
      USER
      ADMIN
    }

    Option A: Starting with an existing database (brownfield)

    If you want to use Lift with an existing database, you can introspect your database schema using the Prisma 2 CLI. This generates a declarative data model which provides the foundation for future migrations.

    Option B: Start from scratch (greenfield)

    When starting from scratch, you can simply write your own data model definition inside your schema file. You can then use the Lift CLI commands to migrate your database (Lift maps your data model definition to the schema of the underlying database).

    3. Adjust the data model

    Instead of sending SQL migration statements to the database, you need to adjust the data model file to describe your desired database schema. You can express any schema migration you like using the new data model, this includes for example adding a new model, removing a model or updating the fields of a model. You can also add indexes or validation constraints in the data model.

    You can create a new migration for your change by running prisma migrate save:

    prisma migrate save --name "add-comment-model"

    4. Migrate your database (apply data model changes)

    Once you're happy with the changes, you can use the Prisma CLI to migrate your database (i.e. map the adjusted data model to your database). Lift's migration engine will generate the corresponding SQL statements and send them to the database for you.

    prisma migrate up

    Supported databases

    Photon JS can be used with the following databases:

    • MySQL
    • PostgreSQL
    • MongoDB (coming very soon)

    More databases that will be supported in the future are:

    • MS SQL
    • Oracle
    • Neo4J
    • FaunaDB
    • ...

    Contributing

    Read more about how to contribute to Prisma Migrate here

    Build status

    Keywords

    none

    Install

    npm i @prisma/lift

    DownloadsWeekly Downloads

    725

    Version

    0.3.384

    License

    Apache-2.0

    Unpacked Size

    444 kB

    Total Files

    215

    Last publish

    Collaborators