laravel でなにか作った後の DB の面倒を見るのがめんどくさいです。なのでcockroachdb みたいに手のかからない DB が使えれば嬉しいです
postgress 互換なので postgress 用の laravel 設定を流用して使えないかなとおもってためしてみたのですが、結論からいうと この issue が解決されないと、laravel で cockroachdb つかうの無理っぽいです
laravel の database.php の pgsql の connections を見るとパスワード認証にしか対応していないので、証明書でログインするように変更します
/*
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
*/
// refer https://gist.github.com/tigusigalpa/2d1ec6e258ed96221abf9679622d274a
'pgsql' => [
'driver' => 'pgsql',
# 'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '26257'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
# 'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'require',
'sslrootcert' => env('DB_SSLROOTCERT', ''),
'sslcert' => env('DB_SSLCERT', ''),
'sslkey' => env('DB_SSLKEY', ''),
],
ついでに port も cockroachdb のデフォルトの 26257 に変更しておきます
sslmode は require に変更して、あと sslrootcert, sslcert, sslkey を .env から読めるように追加しました
laravel で使うための db をつくって、laravel で使うユーザに全権を Grant しておきます
migrate してみると、cockroach にクエリーがきてます o(´∀`)o
なんだ、簡単だったな、とおもったらぬか喜びでした
created_at, pdated_at あたりがエラーになってます
php artisan migrate
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException : SQLSTATE[0A000]: Feature not supported: 7 ERROR: syntax error: unimplemented: unimplemented at or near "zone"
DETAIL: source SQL:
create table "users" ("id" bigserial primary key not null, "name" varchar(255) not null, "email" varchar(255) not null, "email_verified_at" timestamp(0) without time zone null, "password" varchar(255) not null, "remember_token" varchar(100) null, "created_at" timestamp(0) without time zone null, "updated_at" timestamp(0) without time zone null)
^
HINT: See: https://github.com/cockroachdb/cockroach/issues/32098 (SQL: create table "users" ("id" bigserial primary key not null, "name" varchar(255) not null, "email" varchar(255) not null, "email_verified_at" timestamp(0) without time zone null, "password" varchar(255) not null, "remember_token" varchar(100) null, "created_at" timestamp(0) without time zone null, "updated_at" timestamp(0) without time zone null))
なんか親切な HINT がでてるので見てみると、ようは cockroachdb が timestamp の精度指定 にまだ対応してないのが原因みたいです
このissue はそもそも symfony で使おうとしてあがってきたみたいですけど、symfony でダメなら当然、laravel でもだめですね orz
issue が fix されるまでもう少し待とうかなと
Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。
また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!
こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?
コメント