db: Move migrations to require up/down migrations When generating migrations, up/down migrations are revertable. Thus better. This change moves the oldest migration to have both, and thus sqlx will require everyone to create up/down migrations.

zj
Sep 7, 2021, 6:29 PM
EYZMH7NAJNR5BFUSA27Z6RUNAU76PPFDG465SZZQLQF4DPXCMGZQC

Dependencies

  • [2] 5UNA2DEA routes: Register and authenticate users Allow users to sign up, and sign in/sign out. The routes are added, though the design of the pages is very bare bones still, it's hard to go through the full flow to demo. On the server side: Passwords are stored encrypted in the database with salts. This uses the PG encrypt tooling to prevent against bugs and maintainance costs on this project. When a user is signed in, the user ID is set in a private cookie. Rocket has Guards for routes, which has not been implemented yet for this project.
  • [3] IWM4EE63 database: Add migration support Fairly minor change codewise; add support for creating migrations and run them at the start of the runtime. In this case not a lot of changes happen, only the migrations tracking table is added. The sqlx command line tool is used to manage migrations; invoke `cargo sqlx --help` for more info.

Change contents

  • file deletion: 20210813185317_users_table.sql (----------)
    [3.199][2.9353:9407](),[2.9407][2.9408:9408]()
    -- Enable PG crypto helpers we need to store passwords
    CREATE EXTENSION pgcrypto;
    CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(64) NOT NULL,
    email TEXT NOT NULL,
    password TEXT NOT NULL
    );
    CREATE UNIQUE INDEX unique_user_name ON users(name);
    CREATE UNIQUE INDEX unique_user_email ON users(email);
  • file addition: 20210813185317_users_table.up.sql (----------)
    [3.199]
    -- Enable PG crypto helpers we need to store passwords
    CREATE EXTENSION pgcrypto;
    CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(64) NOT NULL,
    email TEXT NOT NULL,
    password TEXT NOT NULL
    );
    CREATE UNIQUE INDEX unique_user_name ON users(name);
    CREATE UNIQUE INDEX unique_user_email ON users(email);
  • file addition: 20210813185317_users_table.down.sql (----------)
    [3.199]
    DROP EXTENSION IF EXISTS pgcrypto;
    DROP TABLE users;