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

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
}

Related

Pulumi: How can a Function App reference a connection string from a SQL Server Database declaration?

Using Pulumi, how can a Function App reference a connection string from a SQL Server Database declaration?
I've tried building the following SQL connection string:
var sqlServer = server as Pulumi.Azure.Sql.SqlServer;
var connectionString = $"Server=tcp:{sqlServer.FullyQualifiedDomainName},1433;Initial Catalog={sqlDatabase.Name};Persist Security Info=False;User ID={sqlServer.AdministratorLogin};Password={sqlServer.AdministratorLoginPassword};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
Unfortunately, the Output<string> property values that are embedded within the connection string, never get resolved after observing the App Settings of an Azure function app.
In Pulumi, does a connection string property exist for an Azure SQL Server database?
The following code resolves a SQL connection string:
var connectionStringArgs = new ConnStringInfoArgs(){
Name = "MySqlDbConnection-dev",
Type = ConnectionStringType.SQLAzure,
ConnectionString = Output.Tuple(sqlServer.Name, sqlDatabase.Name, sqlServer.AdministratorLogin, sqlServer.AdministratorLoginPassword).Apply(t => {
(string server, string database, string username, string pwd) = t;
return
$"Server= tcp:{server}.database.windows.net;initial catalog={database};userID={username};password={pwd};Min Pool Size=0;Max Pool Size=30;Persist Security Info=true;";
}),
};
var connectionString = connectionStringArgs.ConnectionString;

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

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

pg-promise: Update existing connection with new password

I have a use case that many connections to the database are created dynamically using pg-promise. Sometimes I need to connect again to the same database and user however the password changed.
Is there a way to update an existing connection so I dont get the "WARNING: Creating a duplicate database object for the same connection."?
Editing for better explanation:
Context
I have a non-traditional application that is a node service that handles geospatial data aquisition in the software QGIS, with Postgres + PostGIS.
This application creates temporary users in the PostgreSQL server and manage permissions on the tables and columns based on the type of work the user needs to do.
Code
const dbs = {} //global variable that stores all connections
const getConnection = async (user, password, server, port, dbname) => {
const connString = `postgres://${user}:${password}#${server}:${port}/${dbname}`
if (connString in dbs) {
return dbs[connString] //if connection already exists returns the connection
}
dbs[connString] = db.pgp(connString) //create new connection
await dbs[connString] //tests if connections is correct
.connect()
.then(obj => {
obj.done() // success, release connection;
})
.catch(e => {
errorHandler.critical(e)
})
return dbs[connString]
}
What I want is add another case, that if the connection already exists but the password changed it updates the existing connection password (or destroy it and create a new one).
The issue in your case is that you are using password as part of the connection-string key, which isn't used within the library's unique-connection check, hence the side effect.
For the key, you need to use a unique connection string that does not contain the password. And when the request is made, you need to update the connection details.
Example below makes use of the connection object, not the connection string, because it is simpler that way. But if you want, you can use a connection string too, you would just need to generate a separate connection string, with the password, and update $pool.options.connectionString, not $pool.options.password.
const dbs = {}; // global variable that stores all connections
const getConnection = async (user, password, host, port, database) => {
const key = `${user}#${host}:${port}/${database}`; // unique connection key
const cn = { host, port, database, user, password }; // actual connection
let db; // resulting database object
if (key in dbs) {
db = dbs[key];
db.$pool.options.password = password; // updating the password
} else {
db = pgp(cn); // creating new connection
dbs[key] = db;
await db // test if can connect
.connect()
.then(obj => {
obj.done(); // success, release connection;
})
.catch(e => {
errorHandler.critical(e);
throw e;
})
}
return db;
}

How to connect Mongolab with MongoDb.Driver

i'm testing mongolab with .netCore using MongoDb.Driver.
I have this connection string
mongodb://<dbuser>:<dbpassword>#mymongolaburl:46367/somedatabase
And i'm connecting this way
var connectionString = #"mongodb://<dbuser>:<dbpassword>#mymongolaburl:46367/somedatabase";
var databaseName = "somedatabase";
var client = new MongoClient(connectionString);
if (client != null)
{
_database = client.GetDatabase(databaseName);
_database.GetCollection<User>("User").InsertOne(new User {Name="Luke Skywalker" });
}
It is not working 'cause it says the database name is invalid, if i use the connection string without the database name
mongodb://<dbuser>:<dbpassword>#mymongolaburl:46367
I get a timeout execption.
I Already connected to database using Robo 3T.
Thanks in advance.
After one day i found how to do that in this link
The The solution is to specify which is database in the connection string
mongodb://<dbuser>:<dbpassword>#mymongolaburl:46367/?authSource=somedatabase
Thank you!

Unable to connecto to mongoDB

Trying to connect to mongoDB using MongoLab AddOn, I get the following error:
{ "$err" : "not authorized for query on myAppDB.Users", "code" : 13 }
when I run the following code:
private string connectionString = "mongodb://appharbor_93126661-e8b7-4986-958c-74e4ed8401e6:qj0boq192osh10rXXXXXXXX#ds027521.mongolab.com:27521/appharbor_93126661-e8b7-4986-958c-74e4ed8401e6";
private string dbName = "myAppDB";
private string userCollectionName = "Users";
private MongoCollection<User> GetUsersCollection()
{
MongoUrl url = new MongoUrl(connectionString);
MongoClient client = new MongoClient(url);
mongoServer = client.GetServer();
MongoDatabase database = mongoServer.GetDatabase(dbName);
MongoCollection<User> userCollection = database.GetCollection<User>(userCollectionName);
return userCollection;
}
I tried to connect from shell running the command:
mongo ds027521.mongolab.com:27521/appharbor_93126661-e8b7-4986-958c-74e4ed8401e6 -u appharbor_93126661-e8b7-4986-958c-74e4ed8401e6 -p qj0boq192osh10rXXXXXXXX
but also haven't managed to connect.
If anyone encountered similar issue or knows what is causing the problem I would be very thankful for any suggestion in prder to solve the problem.