https://www.prisma.io/ logo
Join Slack
Powered by
# prisma-migrate
  • b

    Barnaby

    07/29/2022, 4:41 PM
    is there an easy way I can just run the migrations for a (simple) postgres database on a local sqlite instance for integration testing?
    โœ… 1
    a
    • 2
    • 4
  • b

    Barnaby

    07/29/2022, 4:42 PM
    I know there's the
    datasource
    bit in the schema, but we can't have multiple of these currently and can't adjust the provider to be
    sqlite
    just for when tests run
  • f

    Fred Lackey

    08/11/2022, 9:55 PM
    any way to force
    prisma migrate
    to use
    UNIQUE NULLS NOT DISTINCT
    instead of
    UNIQUE
    with postgres? i need to support an existing pattern in use in our company for soft deletes by way of a "date deleted" column. the following data would be considered valid with a unique constraint on both "email" and "deleted" ... a "valid" or "undeleted" object would NOT have a value set for the
    deleted
    column thereby allowing the email address to be reused
    Copy code
    {
      id: 2,
      email: "<mailto:joe.blow@nowhere.com|joe.blow@nowhere.com>"
      created: "2022-08-11T21:12:36+00:00",
    },
    {
      id: 2,
      email: "<mailto:joe.blow@nowhere.com|joe.blow@nowhere.com>"
      created: "2011-1-11T11:11:11+00:00",  
      deleted: "2022-2-22T22:22:22+00:00",
    }
    link to a similar question on SO: https://stackoverflow.com/questions/8289100/create-unique-constraint-with-null-columns
    ๐Ÿ‘€ 1
    a
    • 2
    • 1
  • b

    Barnaby

    08/18/2022, 10:20 AM
    Hey is there a way I can run my migrations to a specific point? so like
    prisma migrate reset
    but I want it to stop one migration before the most recent just so I can test my custom migration SQL with real data
  • b

    Barnaby

    08/18/2022, 11:18 AM
    okay, scratch that, new question:
    The migration
    20220204125655_rename_fields_add_new
    was modified after it was applied.
    This migration is from aaaages ago (February) so this is surprising, it comes up every time I try to migrate, I'd rather not clear my database just because of this, how can I resolve this?
    ๐Ÿ‘€ 1
    a
    • 2
    • 3
  • g

    Gustavo

    08/19/2022, 3:58 AM
    Hi guys, I've got a hopefully not unique situation here (multi-tenant architecture), I'd appreciate any inputs/suggestions ๐Ÿ™‚ I have developed an API running on nodejs. that is split into different packages, where each package has its own
    schema.prisma
    e.g.
    Copy code
    - project_folder
    -- migrate.js
    -- src
    ---- index.ts
    ---- packages
    ------- package_1
    ---------- index.ts
    ---------- prisma
    ------------- client
    ------------- migrations
    ------------- schema.prisma
    ------- package_2
    ---------- index.ts
    ---------- prisma
    ------------- client
    ------------- migrations
    ------------- schema.prisma
    package_1 > prisma > schema.prisma
    looks like:
    Copy code
    generator client {
        provider        = "prisma-client-js"
        previewFeatures = ["interactiveTransactions"]
        output          = "./client"
    }
    
    datasource db {
        provider = "mysql"
        url      = env("ORGANISATION_CONTEXT_DATABASE_URL")
    }
    ORGANISATION_CONTEXT_DATABASE_URL
    is always the same for a given env (dev, prod, etc...)
    package_2 > prisma > schema.prisma
    looks like:
    Copy code
    generator client {
        provider        = "prisma-client-js"
        previewFeatures = ["interactiveTransactions"]
        output          = "./client"
    }
    
    datasource db {
        provider = "mysql"
        url      = env("DATABASE_URL")
    }
    DATABASE_URL
    changes depending the user making a request. Everything locally works just fine. The issue I have is at the moment of applying migrations when deploying through github actions. At the moment I'm testing the following. Whenever everything has been deployed run the command:
    ci.yml
    Copy code
    - name: "Run migrations"
         run: yarn migrate
    package.json
    Copy code
    {
      "scripts": {
        "migrate": "node migrate.js"
      }
    }
    migrate.js
    Copy code
    process.env.ORGANISATION_CONTEXT_DATABASE_URL = 'postgressql://....'
    
    const organisationContextSchema='./src/packages/package_1/prisma/prisma.schema'
    const cmd1 = spawnSync('npx', ['prisma', 'generate', `--schema=${organisationContextSchema}`]);
    
    const cmd2 = spawnSync('npx', ['prisma', 'migrate', 'deploy', `--schema=${organisationContextSchema}`]);
    
    // HERE IS WHERE PROBLEMS HAPPEN!!!! :(
    const orgContDbClient = new PrismaClient({
        datasources: { db: { url: process.env.ORGANISATION_CONTEXT_DATABASE_URL } },
    });
    
    console.log('connected! Fetching orgs...');
    const dbOrgs = await orgContDbClient.organisation.findMany();
    
    console.log('dbOrgs: ', dbOrgs);
    Error:
    Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
    ๐Ÿ˜ž
    โœ… 1
    • 1
    • 1
  • b

    Barnaby

    08/24/2022, 9:22 AM
    Yo, is there a way to ignore an existing table entirely? Use-case: we've merged two tables into one, the old table is still there for data science reasons (before we delete it entirely, there's some data in there we want to play with) but I want to remove this table from our
    schema.prisma
    file without it triggering a migration to drop the table. Is this possible? I tried this:
    Copy code
    model companies {
      // deleted every column here and set to ignore
      @@ignore
    }
    but when I run
    prisma migrate dev
    it wants to drop these columns still, I'd rather just hide this table from prisma entirely so it doesn't want to control it any more.
    โœ… 1
    r
    • 2
    • 3
  • n

    Nish Junankar

    09/07/2022, 4:57 PM
    I was wondering if anyone knew how to create a unique constraint on a key in a jsonb column in the prisma.schema file, I know the raw sql to do it but I want to do it via the schema file
    โœ… 1
    a
    • 2
    • 2
  • j

    Jeff Hastings

    09/14/2022, 3:00 PM
    Iโ€™m comparing the output of a schema created with prisma using introspection to the original schema in PostgreSQL, and something with unique constraints stuck out to me. When you create a table using
    UNIQUE
    in postgres, it creates a unique constraint. With Prisma and
    @@unique
    , it just creates a unique index. For example
    Copy code
    model AnotherUser {
      id        Int     @id @default(autoincrement())
      firstName String?
      lastName  String?
    
      @@unique([firstName, lastName])
    }
    Generates the following migration
    Copy code
    -- CreateTable
    CREATE TABLE "AnotherUser" (
        "id" SERIAL NOT NULL,
        "firstName" TEXT,
        "lastName" TEXT,
    
        CONSTRAINT "AnotherUser_pkey" PRIMARY KEY ("id")
    );
    
    -- CreateIndex
    CREATE UNIQUE INDEX "AnotherUser_firstName_lastName_key" ON "AnotherUser"("firstName", "lastName");
    And the table description lists it as simply UNIQUE
    Copy code
    "AnotherUser_firstName_lastName_key" UNIQUE, btree ("firstName", "lastName")
    And I donโ€™t see a constraint in
    pg_constraint
    . BUT if I create the same table with
    UNIQUE
    Copy code
    CREATE TABLE "AnotherUser" (
        "id" SERIAL NOT NULL,
        "firstName" TEXT,
        "lastName" TEXT,
    
        CONSTRAINT "AnotherUser_pkey" PRIMARY KEY ("id"),
        UNIQUE("firstName", "lastName")
    );
    The table description lists the unique constraint
    Copy code
    "AnotherUser_firstName_lastName_key" UNIQUE CONSTRAINT, btree ("firstName", "lastName")
    And I can see the constraint in
    pg_constraint
    Does anyone know why Prisma Migrate is only creating unique indexes and not unique constraints (which are backed by a unique index)?
    ๐Ÿ‘€ 1
    โœ… 1
    n
    • 2
    • 3
  • v

    Vladi Stevanovic

    09/23/2022, 10:44 AM
    ๐Ÿ‘‹ Hello everyone! To streamline support for our Community, all questions about the Prisma ORM (Client, Studio, Migrate) will now be answered in #orm-help channel, and this channel will be archived next week is now archived. We hope that this will allow us to help you more quickly and share the knowledge among all our community members. ๐Ÿ˜Š If you have any pending questions / issues, feel free to resolve them in the current threads or move the conversation into #orm-help! ๐Ÿง‘โ€๐Ÿ’ป Happy coding!
  • s

    Slackbot

    09/23/2022, 7:54 PM
    This message was deleted.
    v
    • 2
    • 2
1...56789Latest