# Database connection
To connect to a database, just update database values inside .env.
# Database drivers
Tea supports Mysql and PostgreSQL.
# Mysql
To use Mysql set DB_CONNECTION to mysql in your .env file and make sure all other configurations are correct.
# PostgreSQL
To use PostgreSQL set DB_CONNECTION to pgsql in your .env file and make sure all other configurations are correct.
# Migrations
To make development easier, Tea comes with database migrations.
To create a new migration, run:
php tea make:migration name=CreateProductsTable table=products
<?php
use Devlob\Database\Migrations\Schema;
use Devlob\Database\Migrations\Blueprint;
class CreateProductsTable
{
public function up()
{
Schema::create('products', function(Blueprint $table) {
$table->id();
return $table;
});
}
public function down()
{
Schema::dropIfExists('products');
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Available data types
Tea is still new, currently it supports the following types:
boolean, enum, id, integer, string, text, unsignedInteger
# boolean
$table->boolean('active')
Boolean data type.
# enum
$table->enum('category', ['comedy', 'action', 'thriller'])
Enum data type.
# id
$table->id()
An unsigned, auto increment integer with the primary key constraint.
# integer
$table->integer('speed')
A second boolean parameter can be passed to set the column as unsigned. Default is false.
Integer data type.
# string
$table->string('name')
A second parameter can be passed for the length. Default is 255.
Varchar data type.
# text
$table->text('description')
Text data type.
# unsignedInteger
$table->unsignedInteger('score')
Unsigned integer data type.
# Available constraints
Tea is still new, currently it supports the following constraints:
default, notNull, primary, unique
# default
$table->boolean('active')->default(true)
It sets a default value to the column.
# notNull
$table->enum('category', ['comedy', 'action', 'thriller'])->notNull()
It makes the column non-nullable.
# primary
$table->integer('id')->primary()
It sets the column as primary.
# unique
$table->string('slug')->unique()
Makes the column unique.
# Chaining
You can also chain constraints:
$table->string('slug')->unique()->notNull()
# Migrating
In order to migrate your new migration, you should run:
composer dump-autoload
php tea migrate:refresh
Tea doesn't keep track of migrations at the moment, those whenever you run migrate:refresh you delete all the tables and re-create them, losing your data.