I am working on rewriting a web app written in php and laravel to a JavaScript stack. At present I am working on reworking the db schema which seems to be mysql to postgres.
I am slightly confused with some of the syntax for the following create table command
public function up()
{
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->unique();
$table->unsignedInteger('user_id')->nullable();
$table->string('ip_address', 45)->nullable();
$table->text('user_agent')->nullable();
$table->text('payload');
$table->integer('last_activity');
});
}
From my understanding the postgres equivalent for the above would be
create table sessions (
id text unique not null,
user_id int references users,
ip_address text,
user_agent text,
payload text,
last_activity integer
);
However I am not sure that I have translated $table->string('ip_address', 45)->nullable(); correctly as I am not sure what exactly string('ip_address', 45) is doing.
Is my transformation to potgres correct or what do I need to change in order to have something equivalent in the postgres create command?
inet(and last_activity sounds more like it should be atimestamp)->string()can be translated into many things in laravel, you can dig laravel's github if you want to know.inetcolumn in laravel migration usingipAddress. it will be translated toinetif you set it to run against postgresql. though, it will benvarchar(45)for sql-server andvarchar(45)for mysql.