数据库准备 postgresql

图形界面 pgAdmin
image.png

配置环境变量

PG_HOME D:\apptools\postgresql
Path %PG_HOME%\bin

psql -d chitchat -U postgres

执行脚本初始化数据库

setup.sql文件

  1. -- drop table posts;
  2. -- drop table threads;
  3. -- drop table sessions;
  4. -- drop table users;
  5. create table users (
  6. id serial primary key,
  7. uuid varchar(64) not null unique,
  8. name varchar(255),
  9. email varchar(255) not null unique,
  10. password varchar(255) not null,
  11. created_at timestamp not null
  12. );
  13. create table sessions (
  14. id serial primary key,
  15. uuid varchar(64) not null unique,
  16. email varchar(255),
  17. user_id integer references users(id),
  18. created_at timestamp not null
  19. );
  20. create table threads (
  21. id serial primary key,
  22. uuid varchar(64) not null unique,
  23. topic text,
  24. user_id integer references users(id),
  25. created_at timestamp not null
  26. );
  27. create table posts (
  28. id serial primary key,
  29. uuid varchar(64) not null unique,
  30. body text,
  31. user_id integer references users(id),
  32. thread_id integer references threads(id),
  33. created_at timestamp not null
  34. );
  1. psql -f .\setup.sql -d chitchat -U postgres

image.png