schema_version_1.sql 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. create table schema_version (
  2. version text not null
  3. );
  4. create table users (
  5. id serial not null,
  6. username text not null unique,
  7. password text,
  8. is_admin bool default 'f',
  9. language text default 'en_US',
  10. timezone text default 'UTC',
  11. theme text default 'default',
  12. last_login_at timestamp with time zone,
  13. primary key (id)
  14. );
  15. create table sessions (
  16. id serial not null,
  17. user_id int not null,
  18. token text not null unique,
  19. created_at timestamp with time zone default now(),
  20. user_agent text,
  21. ip text,
  22. primary key (id),
  23. unique (user_id, token),
  24. foreign key (user_id) references users(id) on delete cascade
  25. );
  26. create table categories (
  27. id serial not null,
  28. user_id int not null,
  29. title text not null,
  30. primary key (id),
  31. unique (user_id, title),
  32. foreign key (user_id) references users(id) on delete cascade
  33. );
  34. create table feeds (
  35. id bigserial not null,
  36. user_id int not null,
  37. category_id int not null,
  38. title text not null,
  39. feed_url text not null,
  40. site_url text not null,
  41. checked_at timestamp with time zone default now(),
  42. etag_header text default '',
  43. last_modified_header text default '',
  44. parsing_error_msg text default '',
  45. parsing_error_count int default 0,
  46. primary key (id),
  47. unique (user_id, feed_url),
  48. foreign key (user_id) references users(id) on delete cascade,
  49. foreign key (category_id) references categories(id) on delete cascade
  50. );
  51. create type entry_status as enum('unread', 'read', 'removed');
  52. create table entries (
  53. id bigserial not null,
  54. user_id int not null,
  55. feed_id bigint not null,
  56. hash text not null,
  57. published_at timestamp with time zone not null,
  58. title text not null,
  59. url text not null,
  60. author text,
  61. content text,
  62. status entry_status default 'unread',
  63. primary key (id),
  64. unique (feed_id, hash),
  65. foreign key (user_id) references users(id) on delete cascade,
  66. foreign key (feed_id) references feeds(id) on delete cascade
  67. );
  68. create index entries_feed_idx on entries using btree(feed_id);
  69. create table enclosures (
  70. id bigserial not null,
  71. user_id int not null,
  72. entry_id bigint not null,
  73. url text not null,
  74. size int default 0,
  75. mime_type text default '',
  76. primary key (id),
  77. foreign key (user_id) references users(id) on delete cascade,
  78. foreign key (entry_id) references entries(id) on delete cascade
  79. );
  80. create table icons (
  81. id bigserial not null,
  82. hash text not null unique,
  83. mime_type text not null,
  84. content bytea not null,
  85. primary key (id)
  86. );
  87. create table feed_icons (
  88. feed_id bigint not null,
  89. icon_id bigint not null,
  90. primary key(feed_id, icon_id),
  91. foreign key (feed_id) references feeds(id) on delete cascade,
  92. foreign key (icon_id) references icons(id) on delete cascade
  93. );