You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATETABLEusers (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
created DATETIME,
modified DATETIME
);
CREATETABLEbookmarks (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INTNOT NULL,
title VARCHAR(50),
description TEXT,
url TEXT,
created DATETIME,
modified DATETIME,
FOREIGN KEY user_key (user_id) REFERENCES users(id)
);
CREATETABLEtags (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
created DATETIME,
modified DATETIME,
UNIQUE KEY (title)
);
CREATETABLEbookmarks_tags (
bookmark_id INTNOT NULL,
tag_id INTNOT NULL,
PRIMARY KEY (bookmark_id, tag_id),
FOREIGN KEY tag_key(tag_id) REFERENCES tags(id),
FOREIGN KEY bookmark_key(bookmark_id) REFERENCES bookmarks(id)
);
Show tables were created
show tables;
Explain a couple tables
explain bookmarks;
explain tags;
Exit MySQL
Show one more time the file system
Now it's time to do some baking
First edit the Database configuration
vi config/app.php
Search for Datasource and update the connection information
Bake stuff
bin/cake bake all users
bin/cake bake all bookmarks
bin/cake bake all tags
Demo using the CRUD system
Show the weird step of needing to add hashing to the user model
vi src/Model/Entity/User.php
Add
useCake\Auth\DefaultPasswordHasher;
/* Code from the bake, then also add */protectedfunction_setPassword($value)
{
$hasher = newDefaultPasswordHasher();
return$hasher->hash($value);
}
Turn of Foreign key checking and truncate data
SET FOREIGN_KEY_CHECKS = 0;
truncate bookmarks;
truncate users;
SET FOREIGN_KEY_CHECKS = 1;
New table called phinxlog which captures the migrations as well as a posts table
explain posts;
Take a second to create migrations for the other tables. We will exclude the Posts table by adding the --require-table switch to Initial. Since we haven't created a model for Posts yet this should exclude the creation of the migration.