how to form url in prisma.schema file using system variable - prisma

generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = "postgresql://${app_db_username}:${app_db_password}#${endpoint}/${dbname}?schema=public"
}
I'm trying to form the below url, so how to use it

String concatenation is not implemented in Prisma yet. As of now you need to provide an environment variable that contains full database url:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
You can use an .env file to prepare the environment variable (Prisma v2.7.0+):
# .env
DATABASE_URL=postgresql://${app_db_username}:${app_db_password}#${endpoint}/${dbname}?schema=public

Related

Error Prisma with Supabase ; db error: FATAL: server login has been failing

I recently started using Prisma and I wanted to use it with supabase so I created my schema and settings up all environement variables but when I migrate here is the error (The password is correct in my .env)
Error: db error: FATAL: server login has been failing, try again later (server_login_retry)
0: migration_core::state::DevDiagnostic
at migration-engine\core\src\state.rs:269
And here is my schema.prisma :
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
model Items {
i_id Int #id #default(autoincrement())
i_name String
i_image String
i_quantity Int
}

Error protecting file using MIP SDK in service/daemon application

can someone help me with the following issue?
Scenario. I have a Windows Service running on an Azure VM. Service receives files, modifies them in some way (let's assume that it adds custom properties to Word files) and uses MIP SDK to protect them with template ID.
Issue. IFileHandler.SetProtection(string)+CommitAsync(...) fails with the following exception:
One or more errors occurred. ServiceDiscoveryHelper::GetServiceDetails - Cannot compute domain: license domains, identity, and cloud endpoint base URL are all empty, correlationId:[9add32ba-0cb7-4d31-b9d8-0000b7c694a4]
Other info
RemoveProtection()+CommitAsync(...) work fine.
I registered application in Azure Active Directory tenant.
Generated secret: <CLIENT_SECRET>.
Granted the following permissions
https://api.mipwebservice.com/InformationProtectionPolicy.Read.All
https://psor.o365syncservice.com/UnifiedPolicy.Tenant.Read
https://aadrm.com/Content.SuperUser
https://aadrm.com/Content.Writer
https://aadrm.com/Content.DelegatedWriter
https://aadrm.com/Content.DelegatedReader
IAuthDelegate implementation
uses ADAL to get access token using client_credentials authentication flow, because there is no interacting user (my app is service).
I do not whether I have to use identity parameter in client_credentials flow.
Main Code Snippet
MIP.Initialize(MipComponent.File);
var appInfo = new ApplicationInfo{
ApplicationId = ConfigurationManager.AppSettings["AppPrincipalId"],
ApplicationName = "App name",
ApplicationVersion = "1.0.0",
};
var authDelegate = new AuthDelegateImplementation(appInfo);
var fileProfileSettings = new FileProfileSettings("mip_data", false,
authDelegate, new ConsentDelegateImplementation(), appInfo, LogLevel.Trace);
var fileProfile = MIP.LoadFileProfileAsync(fileProfileSettings).Result;
var engineSettings = new FileEngineSettings("engine-id", "", "en-US"){
Identity = new Identity($"{appInfo.ApplicationId}#<TENANT-NAME>"){
DelegatedEmail = "<OWNER>#<TENANT-NAME>",
},
};
var fileEngine = fileProfile.AddEngineAsync(engineSettings).Result;
var fileHandler = fileEngine.CreateFileHandlerAsync("c:\\sample.docx", "0", true).Result;
fileHandler.SetProtection(new ProtectionDescriptor("<TEMPLATE-ID>"));
var success = fileHandler.CommitAsync("c:\\encrypted.docx").Result;
AuthDelegateImplementation
public string AcquireToken(Identity identity, string authority, string resource)
var authContext = new AuthenticationContext(authority + "/" + "<TENANT_ID>");
var clientCredential = new ClientCredential("<CLENT_ID>", "<CLIENT_SECRET>");
var res = await authContext.AcquireTokenAsync(resource, clientCredential);
return res.AccessToken;
}
ConsentDelegateImplementation
public class ConsentDelegateImplementation : IConsentDelegate {
public Consent GetUserConsent(string url) {
return Consent.Accept;
}
}
It seams that after testing MIP's local persistent state (see FileProfileSettings.Path property when UseInMemoryStorage is flase) was corrupted. After removing "mip_data" folder issue disappeared.

Setting up database connection using Vapor framework

I'm trying to build APIs using Swift and I've chosen to use Vapor.
I've created a SQLite database and am able to connect to it using a DB client.
Now I want my Swift Vapor project to connect to it as well using the FluentSQLite package.
I've created my database in the root folder of my project:
/Users/rutgerhuijsmans/Documents/runk-3.0
My database is called runk-3.0-database
The folder looks like this:
I try to connect to my DB using the following configuration:
import FluentSQLite
import Vapor
/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
/// Register providers first
try services.register(FluentSQLiteProvider())
/// Register routes to the router
let router = EngineRouter.default()
try routes(router)
services.register(router, as: Router.self)
/// Register middleware
var middlewares = MiddlewareConfig() // Create _empty_ middleware config
/// middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory
middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response
services.register(middlewares)
let sqlite: SQLiteDatabase?
do {
sqlite = try SQLiteDatabase(storage: .file(path: "runk-3.0-database"))
print("data base connected") // This gets printed
/// Register the configured SQLite database to the database config.
var databases = DatabasesConfig()
databases.add(database: sqlite!, as: .sqlite)
services.register(databases)
/// Configure migrations
var migrations = MigrationConfig()
migrations.add(model: User.self, database: .sqlite)
services.register(migrations)
} catch {
print("couldn't connect") // This doesn't get printed
}
}
What am I doing wrong?
As IMike17 explained, your code just creates the new DB file into the Build/Products/Debug or release folder. You have to set full path dynamically as below:
do {
let directory = DirectoryConfig.detect()
let filePath = directory.workDir + "runk-3.0-database"
sqlite = try SQLiteDatabase(storage: .file(path: filePath))
......
Using the .file(path: "runk-3.0-database") the method, if you specify only the name, creates a database file with the specified name in the Derived Data folder. If the file exists in the Derived Data folder, SQLiteDatabase uses it. So the DB is erased when cleaning the build folder.
The console prints out the path of the Derived Data where you can find the DB:
Running default command: /Users/username/Library/Developer/Xcode/DerivedData/SQLiteDB-xxxxxxxxxxxxxxxxxxxxxxx/Build/Products/Debug/
If you use a full path to the DB in your project then the file is used.
Change your init method as follows and you should be good to go for a local environment:
sqlite = try SQLiteDatabase(storage: .file(path: "/Users/rutgerhuijsmans/Documents/runk-3.0/runk-3.0-database"))

How do I access environment variables in config SailsJS

I'm trying to access my environment variables inside a config file. Can I use this variable inside a config?
For example
// config/env/development.js
module.exports = {
appUrl: 'http://MY_DEV_PLACE/',
}
//config/passport.js
var appUrl = appUrl || sails.config.appUrl || 'localhost:1337'; //<-- sails is not defined
I also tried in local.js:
// config/local.js
module.exports = {
gAPI: { secret: 'aaa'}
}
//config/passport.js
var appUrl = gAPI || sails.config.gAPI || 'some pass'; //<-- sails is not defined
EDIT:
For appURL I'm using env like: APP_URL=http://example.com/api sails lift
For password I'm using:
var locals;
try {
locals = require('./local');
} catch (e) {
// not local so just ignore
}
module.exports.passport = {
'GoogleAPI.Password': locals ? locals.gAPI.secret : ’some key'
};
You can use the local.js file for environment variables. This file is discussed in-depth here. This is pretty much the go to for storing environment variables in sails.
Important caveats: make sure this file is included in your .gitignore file lest you risk exposing important information to the world, this file will need to be configured for each environment (e.g. local, staging, production), you can access your environment variables via sails.config.variable_name, this file will take priority over the development.js and production.js file in the /env/ sub-directory.
I accessed the sails object from the routes.js like this:
module.exports.routes = {
'/': (req, res) => {
res.redirect(sails.config.frontendUrl)
}
}
In config/global.js add the following line....
sails: true,
This makes sails instance global.

Using Postgres with Grails

Has anyone gotten Grails working with Postgres? I have used this tutorial and everything seems to make sense and be correct to me. However when I 'grails run-app' I get this error
Cannot create JDBC driver of class 'org.postgresql.Driver' for connect URL 'jdbc:postgres://10.0.0.21/tribes'
java.sql.SQLException: No suitable driver
My DataSource file is
dataSource {
pooled = true
driverClassName = "org.postgresql.Driver"
dialect = org.hibernate.dialect.PostgreSQLDialect
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update"
url = "jdbc:postgres://10.0.0.21:5432/tribes"
username = "grails"
password = "grails"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:postgres://10.0.0.21:5432/tribes"
username = "grails"
password = "grails"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:postgres://10.0.0.21:5432/tribes"
username = "grails"
password = "grails"
}
}
}
From the FAQ: "[if] you get a runtime error that says 'No suitable driver found', it is likely that the URL passed to DriverManager.getConnection is malformed or otherwise incorrect". So what's wrong with yours? Well, the examples in the tutorial look like this:
jdbc:postgresql://localhost:5432/grails
Yours looks like this:
jdbc:postgres://10.0.0.21:5432/tribes
I'm guessing those missing two letters are causing your trouble.
In the BuildConfig.groovy file uncomment the external maven repositories and then add this line
runtime 'postgresql:postgresql:9.0-801.jdbc4' in the dependencies section