DBMate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers. We have pre-installed it in your devcontainer
After that we can setup our migrations folder and the create a users migration.
# Creating migration: crates/db/migrations/20220330110026_user_tables.sql
Edit the SQL file that was generated for you and add the following.
-- migrate:up
(
id SERIAL PRIMARY KEY,
email VARCHAR NOT NULL UNIQUE,
created_at TIMESTAMP NOT NULL DEFAULT NOW ,
updated_at TIMESTAMP NOT NULL DEFAULT NOW
);
INSERT INTO users(email) VALUES('[email protected]');
INSERT INTO users(email) VALUES('[email protected]');
INSERT INTO users(email) VALUES('[email protected]');
-- migrate:down
users;
List the migrations so we can see which have run.
#[ ] 20220330110026_user_tables.sql
#
#Applied: 0
#Pending: 1
Run our new migration.
#Applying: 20220330110026_user_tables.sql
And check that it worked.
And you should see
()
Your project folders should now look like this.