@amplication/plugin-db-mongo
Advanced tools
Comparing version 1.4.3 to 1.4.4
{ | ||
"name": "@amplication/plugin-db-mongo", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"description": "Use a Mongo database in a service generated by Amplication", | ||
@@ -16,3 +16,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@amplication/code-gen-types": "^2.0.1", | ||
"@amplication/code-gen-types": "^2.0.4", | ||
"@babel/parser": "^7.18.11", | ||
@@ -19,0 +19,0 @@ "@babel/types": "^7.18.10", |
@@ -11,5 +11,9 @@ # @amplication/plugin-db-mongo | ||
It updates the following parts: | ||
- Updates the datasource on the `schema.prisma` file | ||
- Updates the datasource on the `schema.prisma` file: | ||
- For versions older than `1.3.3` the datesource name is based on the database type | ||
- MongoDB - the datasource name is `mongo` | ||
- From version `1.3.3` the datasource name is `db`, no matter what is the database type | ||
- From version `1.3.3` as the datasouce name is `db`, all the custom attributes that use the `@{datasource.name}.{nameOfTheAttribute}` are replaced with `@db.{nameOfTheAttribute}` | ||
- Adds the requires services and variables to `docker-compose.yml` | ||
- Replaces the `docker-compose-db.yml` | ||
- Add the `db` service to the `docker-compose.dev.yml` | ||
- Add the requires environment variables to `.env` | ||
@@ -16,0 +20,0 @@ - Update package json file in order to support only the relevant prisma mongo commands |
@@ -58,8 +58,45 @@ import { CreateServerDockerComposeParams } from "@amplication/code-gen-types"; | ||
export const updateDockerComposeDevProperties: CreateServerDockerComposeParams["updateProperties"] = | ||
[ | ||
{ | ||
services: { | ||
db: { | ||
image: "mongo", | ||
ports: ["${DB_PORT}:27017"], | ||
environment: { | ||
MONGO_INITDB_ROOT_USERNAME: "${DB_USER}", | ||
MONGO_INITDB_ROOT_PASSWORD: "${DB_PASSWORD}", | ||
MONGO_INITDB_DATABASE: "${DB_NAME}", | ||
MONGO_REPLICA_SET_NAME: "rs0", | ||
}, | ||
restart: "always", | ||
entrypoint: [ | ||
"/bin/bash", | ||
"-c", | ||
"openssl rand -base64 741 > /data/cert.crt; chmod 400 /data/cert.crt && chown 999 /data/cert.crt; /usr/local/bin/docker-entrypoint.sh mongod --bind_ip_all --keyFile /data/cert.crt --replSet rs0", | ||
], | ||
healthcheck: { | ||
test: "test $$(mongosh --quiet -u $${MONGO_INITDB_ROOT_USERNAME} -p $${MONGO_INITDB_ROOT_PASSWORD} --eval \"try { rs.initiate({ _id: 'rs0', members: [{ _id: 0, host: 'db' }] }).ok } catch (_) { rs.status().ok }\") -eq 1", | ||
start_period: "5s", | ||
interval: "10s", | ||
timeout: "10s", | ||
}, | ||
volumes: [`${mongodbVolumeName}:/var/lib/mongosql/data`], | ||
}, | ||
}, | ||
volumes: { | ||
[mongodbVolumeName]: null, | ||
}, | ||
}, | ||
]; | ||
const DATASOURCE_NAME = "db"; | ||
const URL_NAME = "DB_URL"; | ||
export const dataSource: DataSource = { | ||
name: "mongo", | ||
name: DATASOURCE_NAME, | ||
provider: DataSourceProvider.MongoDB, | ||
url: { | ||
name: "DB_URL", | ||
name: URL_NAME, | ||
}, | ||
}; |
@@ -26,3 +26,7 @@ import { | ||
import { ReferentialActions, ScalarType } from "prisma-schema-dsl-types"; | ||
import { dataSource, updateDockerComposeProperties } from "./constants"; | ||
import { | ||
dataSource, | ||
updateDockerComposeDevProperties, | ||
updateDockerComposeProperties, | ||
} from "./constants"; | ||
import { getPluginSettings } from "./utils"; | ||
@@ -42,5 +46,4 @@ | ||
}, | ||
CreateServerDockerComposeDB: { | ||
before: this.beforeCreateServerDockerComposeDB, | ||
after: this.afterCreateServerDockerComposeDB, | ||
CreateServerDockerComposeDev: { | ||
before: this.beforeCreateServerDockerComposeDev, | ||
}, | ||
@@ -132,20 +135,10 @@ CreatePrismaSchema: { | ||
beforeCreateServerDockerComposeDB( | ||
beforeCreateServerDockerComposeDev( | ||
context: DsgContext, | ||
eventParams: CreateServerDockerComposeDBParams | ||
) { | ||
context.utils.skipDefaultBehavior = true; | ||
eventParams.updateProperties.push(...updateDockerComposeDevProperties); | ||
return eventParams; | ||
} | ||
async afterCreateServerDockerComposeDB( | ||
context: DsgContext | ||
): Promise<ModuleMap> { | ||
const staticPath = resolve(__dirname, "./static/docker-compose"); | ||
return await context.utils.importStaticModules( | ||
staticPath, | ||
context.serverDirectories.baseDirectory | ||
); | ||
} | ||
async afterCreateServerStaticFiles( | ||
@@ -292,2 +285,14 @@ context: DsgContext, | ||
const { entities } = eventParams; | ||
entities.forEach((entity) => { | ||
entity.fields.forEach((field) => { | ||
if (field.customAttributes) { | ||
field.customAttributes = field.customAttributes.replace( | ||
/@([\w]+)\./g, | ||
`@${dataSource.name}.` | ||
); | ||
} | ||
}); | ||
}); | ||
return { | ||
@@ -294,0 +299,0 @@ ...eventParams, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
202987
2373
43
17
1