-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.php
34 lines (26 loc) · 828 Bytes
/
migrate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require_once __DIR__ . "/vendor/autoload.php";
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$createUsersSql = "CREATE TABLE IF NOT EXISTS users (
id VARCHAR(256) PRIMARY KEY,
name VARCHAR(256) NOT NULL,
username VARCHAR(256) NOT NULL
);";
$createTweetsSql = "CREATE TABLE IF NOT EXISTS tweets (
id VARCHAR(256) PRIMARY KEY,
text VARCHAR(256) NOT NULL,
author VARCHAR(256) NOT NULL,
FOREIGN KEY (author) REFERENCES users(id) ON DELETE CASCADE
);";
$dbName = $_ENV["DB_DATABASE"];
$dbPassword = $_ENV["DB_PASSWORD"];
$dbHost = $_ENV["DB_HOST"];
$dbUsername = $_ENV["DB_USERNAME"];
$pdo = new PDO(
"mysql:dbname=$dbName;host=$dbHost",
$dbUsername,
$dbPassword
);
($pdo->prepare($createUsersSql))->execute();
($pdo->prepare($createTweetsSql))->execute();