Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[feature] can you support postgresql? #411

@zhangmazi

Description

@zhangmazi

i have try change codes to install on postgresql, but the result have some errors.

eg.

  1. pq, insert PK(id) issue. (artisan lavalite:install)

codes
file: vendor/lavalite/framework/src/Litepie/Install/Installers/Scripts/ConfigureDatabase.php

`
public function fire(Command $command)
{
$this->command = $command;

    $connected = false;

    // while (!$connected) {
        // $host = $this->askDatabaseHost();
        // $username = $this->askDatabaseUsername();
        // $password = $this->askDatabasePassword();
        // $database = $this->askDatabaseName();

        $host = '127.0.0.1';
        $port = '5432';
        $username = 'user_dev';
        $password = '6666666';
        $database = 'lavalite_cms';

        if ($this->databaseConnectionIsValid($host, $port, $username, $password, $database)) {
            config(['database.connections.pgsql.host' => $host]);
            config(['database.connections.pgsql.port' => $port]);
            config(['database.connections.pgsql.username' => $username]);
            config(['database.connections.pgsql.password' => $password]);
            config(['database.connections.pgsql.database' => $database]);
            $connected = true;
        } else {
            $command->error('Please ensure your database credentials are valid.');
        }
     }
    if ($connected) {
        $this->env->write($database, $username, $password, $host);
        $command->info('Database successfully configured.');
    }

}


protected function databaseConnectionIsValid($host, $port, $username, $password, $database)
{
    try {
        // $link = @mysqli_connect($host, $username, $password, $database);
        $pgConnectionString = sprintf('host=%s port=%d dbname=%s user=%s password=%s', $host, $port, $username, $password, $database);
        var_dump($pgConnectionString);
        $link = @pg_connect($pgConnectionString);

        if (!$link) {
            return false;
        }

        return true;
    } catch (Exception $e) {
        return false;
    }
}

}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions