-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat/deploy-automation * feat/multi-schema-support * feat/dep-update
- Loading branch information
Nicolae-Rares Ailincai
authored
Mar 17, 2023
1 parent
bd0a85d
commit cd06fcb
Showing
13 changed files
with
785 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Publish to NPM | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build: | ||
name: Build & Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js 19.0 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 19.0 | ||
cache: "yarn" | ||
- name: Install Dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Tests | ||
run: yarn test | ||
- name: Build | ||
run: yarn build | ||
|
||
publish-npm: | ||
name: Publish | ||
needs: build | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: NPM | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js 19.0 | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 19.0 | ||
cache: "yarn" | ||
registry-url: https://registry.npmjs.org/ | ||
- name: Install Dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Build | ||
run: yarn build | ||
- name: Publish | ||
run: npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,4 +108,4 @@ bin | |
prisma | ||
prisma-mapper.json | ||
.DS_Store | ||
out.prisma | ||
out*.prisma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"trailingComma": "none", | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
generator client { | ||
provider = "mock" | ||
previewFeatures = ["metrics", "multiSchema"] | ||
binaryTargets = [env("mock"), "mock"] | ||
engineType = "mock" | ||
output = env("mock") | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
schemas = ["base", "transactional"] | ||
} | ||
|
||
model ModelOne { | ||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid | ||
someId Int @unique @map("some_id") | ||
json Json? @db.Json | ||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) | ||
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) | ||
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6) | ||
@@index([deletedAt, someId], map: "index_name") | ||
@@map("model_one") | ||
@@schema("base") | ||
} | ||
|
||
model ModelTwo { | ||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid | ||
string String? @db.VarChar(255) | ||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) | ||
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) | ||
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6) | ||
someInt Int @map("some_int") | ||
someUuid String? @map("some_uuid") @db.Uuid | ||
ModelThree ModelThree[] | ||
@@index([deletedAt, createdAt(sort: Desc)], map: "index_name_2") | ||
@@map("model_two") | ||
@@schema("transactional") | ||
} | ||
|
||
model ModelThree { | ||
modelTwoId String @db.Uuid | ||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) | ||
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) | ||
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6) | ||
ModelTwo ModelTwo @relation(fields: [modelTwoId], references: [id], onDelete: Cascade) | ||
@@id([modelTwoId], map: "index_name_3") | ||
@@map("model_three") | ||
@@schema("base") | ||
} | ||
|
||
model ModelFour { | ||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid | ||
enumOne EnumOne @default(SomeValue) @map("enum_one") | ||
enumTwo EnumTwo? @map("enum_two") | ||
enumThree EnumThree? @map("enum_three") | ||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6) | ||
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) | ||
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6) | ||
@@map("model_four") | ||
@@schema("transactional") | ||
} | ||
|
||
enum EnumOne { | ||
SomeValue @map("some_value") | ||
Single @map("single") | ||
@@map("enum_one") | ||
@@schema("base") | ||
} | ||
|
||
enum EnumTwo { | ||
SOME_VALUE | ||
SINGLE | ||
@@map("enum_two") | ||
@@schema("transactional") | ||
} | ||
|
||
enum EnumThree { | ||
SomeValue @map("someValue") | ||
Single @map("single") | ||
@@map("enum_three") | ||
@@schema("base") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Command } from 'commander'; | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
import mapCommand, { action } from '../commands/map'; | ||
import CLIError from '../CLIError'; | ||
|
||
const EXPECTED_PRISMA = path.join(__dirname, 'expected-multi-schema.prisma'); | ||
const OUTPUT_PRISMA = path.join(__dirname, 'out-multi-schema.prisma'); | ||
const MOCK_PRISMA = path.join(__dirname, 'mock-multi-schema.prisma'); | ||
|
||
describe('Test map command with multiSchema feature', () => { | ||
let expectedPrisma = ''; | ||
|
||
beforeAll(async () => { | ||
const programMock = { | ||
command: jest.fn().mockReturnValue({ | ||
description: jest.fn().mockReturnValue({ | ||
action: jest.fn() | ||
}) | ||
}) | ||
} as unknown as Command; | ||
|
||
mapCommand(programMock); | ||
|
||
expectedPrisma = await fs.readFile(EXPECTED_PRISMA, 'utf-8'); | ||
}); | ||
|
||
it('command should pass', async () => { | ||
await action( | ||
{ schema: MOCK_PRISMA, output: OUTPUT_PRISMA, camel: true }, | ||
true | ||
); | ||
|
||
expect(expectedPrisma).not.toEqual(''); | ||
|
||
const outputPrisma = await fs.readFile(OUTPUT_PRISMA, 'utf-8'); | ||
expect(outputPrisma).toEqual(expectedPrisma); | ||
}); | ||
|
||
it('command should fail with no schema found', async () => { | ||
try { | ||
await action({ schema: '', camel: true }); | ||
throw new Error('Should not reach here'); | ||
} catch (e) { | ||
const error = e as CLIError; | ||
expect(error.message).toEqual('No prisma schema found'); | ||
expect(error.name).toEqual('CLIError'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
generator client { | ||
provider = "mock" | ||
previewFeatures = ["metrics", "multiSchema"] | ||
binaryTargets = [env("mock"), "mock"] | ||
engineType = "mock" | ||
output = env("mock") | ||
} | ||
|
||
datasource db { | ||
provider = "postgresql" | ||
url = env("DATABASE_URL") | ||
schemas = ["base", "transactional"] | ||
} | ||
|
||
model model_one { | ||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid | ||
some_id Int @unique | ||
json Json? @db.Json | ||
created_at DateTime @default(now()) @db.Timestamptz(6) | ||
updated_at DateTime? @db.Timestamptz(6) | ||
deleted_at DateTime? @db.Timestamptz(6) | ||
@@index([deleted_at, some_id], map: "index_name") | ||
@@schema("base") | ||
} | ||
|
||
model model_two { | ||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid | ||
string String? @db.VarChar(255) | ||
created_at DateTime @default(now()) @db.Timestamptz(6) | ||
updated_at DateTime? @db.Timestamptz(6) | ||
deleted_at DateTime? @db.Timestamptz(6) | ||
some_int Int | ||
some_uuid String? @db.Uuid | ||
model_three model_three[] | ||
@@index([deleted_at, created_at(sort: Desc)], map: "index_name_2") | ||
@@schema("transactional") | ||
} | ||
|
||
model model_three { | ||
model_two_id String @db.Uuid | ||
created_at DateTime @default(now()) @db.Timestamptz(6) | ||
updated_at DateTime? @db.Timestamptz(6) | ||
deleted_at DateTime? @db.Timestamptz(6) | ||
model_two model_two @relation(fields: [model_two_id], references: [id], onDelete: Cascade, onUpdate: NoAction) | ||
@@id([model_two_id], map: "index_name_3") | ||
@@schema("base") | ||
} | ||
|
||
model model_four { | ||
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid | ||
enum_one enum_one @default(some_value) | ||
enum_two enum_two? | ||
enum_three enum_three? | ||
created_at DateTime @default(now()) @db.Timestamptz(6) | ||
updated_at DateTime? @db.Timestamptz(6) | ||
deleted_at DateTime? @db.Timestamptz(6) | ||
@@schema("transactional") | ||
} | ||
|
||
enum enum_one { | ||
some_value | ||
single | ||
@@schema("base") | ||
} | ||
|
||
enum enum_two { | ||
SOME_VALUE | ||
SINGLE | ||
@@schema("transactional") | ||
} | ||
|
||
enum enum_three { | ||
someValue | ||
single | ||
@@schema("base") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.