Browse Source

Update schema

master
Alfred 8 months ago
parent
commit
98cdd0c80c
3 changed files with 32 additions and 58 deletions
  1. 17
    10
      pgsql/fake_data.pgsql
  2. 14
    47
      pgsql/schema.pgsql
  3. 1
    1
      src/App.vue

+ 17
- 10
pgsql/fake_data.pgsql View File

@@ -1,14 +1,20 @@
1
-insert into macarrodes.t_folders (parent, name) values 
2
-    (null, 'news'),
3
-    (null, 'software'),
4
-    (2, 'python');
1
+insert into macarrodes.t_bookmarks (title, url, date_add, site, favicon, nclicks) values 
2
+    ('Hacker News', 'https://news.ycombinator.com/active', '1963-09-01', 'news.ycombinator.com', 'https://news.ycombinator.com/y18.gif', 5), 
3
+    ('Meneame', 'https://www.meneame.net/', '2017-10-01', 'www.meneame.net', 'https://mnmstatic.net/v_144/favicon.ico?v=E6bENepwgd', 2),
4
+    ('Hipertextual', 'https://hipertextual.com/', '2017-05-10', 'hipertextual.com', 'https://hipertextual.com/files/2016/07/cropped-fav-120x120.png', 10),
5
+    ('Espinof', 'https://www.espinof.com/', '2018-09-01', 'www.espinof.com', 'https://img.weblogssl.com/css/espinof/p/skin-site-default-d/images/favicon.ico', 3),
6
+    ('Fetlife', 'https://fetlife.com', '1963-09-01', 'fetlife.com', 'https://pbs.twimg.com/profile_images/1004502321387188224/0u7PBn0l_400x400.jpg', 3);
5 7
 
6
-insert into macarrodes.t_bookmarks (title, url, date_add, folder, site, favicon, nclicks) values 
7
-    ('Hacker News', 'https://news.ycombinator.com/active', '1963-09-01', 1, 'news.ycombinator.com', 'https://news.ycombinator.com/y18.gif', 5), 
8
-    ('Meneame', 'https://www.meneame.net/', '2017-10-01', 1, 'www.meneame.net', 'https://mnmstatic.net/v_144/favicon.ico?v=E6bENepwgd', 2),
9
-    ('Hipertextual', 'https://hipertextual.com/', '2017-05-10', null, 'hipertextual.com', 'https://hipertextual.com/files/2016/07/cropped-fav-120x120.png', 10),
10
-    ('Espinof', 'https://www.espinof.com/', '2018-09-01', 2, 'www.espinof.com', 'https://img.weblogssl.com/css/espinof/p/skin-site-default-d/images/favicon.ico', 3),
11
-    ('Fetlife', 'https://fetlife.com', '1963-09-01', 3, 'fetlife.com', 'https://pbs.twimg.com/profile_images/1004502321387188224/0u7PBn0l_400x400.jpg', 3);
8
+insert into macarrodes.t_tags (name) values 
9
+    ('Read it later'),
10
+    ('Favorite'),
11
+    ('In initial page'),
12
+    ('Useful');
13
+
14
+insert into macarrodes.t_folders (tag, folder_type) values 
15
+    (1, 'readitlater'),
16
+    (2, 'buttons'),
17
+    (3, 'bookmarkslist');
12 18
 
13 19
 insert into macarrodes.t_tags (name) values 
14 20
     ('Aggregator'),
@@ -22,4 +28,5 @@ insert into macarrodes.t_bookmarks_tags (bookmark, tag) values
22 28
     (2, 3),
23 29
     (3, 5),
24 30
     (3, 6),
31
+    (4, 2),
25 32
     (4, 5);

+ 14
- 47
pgsql/schema.pgsql View File

@@ -1,11 +1,5 @@
1 1
 create schema macarrodes;
2 2
 
3
-create table macarrodes.t_folders (
4
-  id serial primary key,
5
-  parent integer references macarrodes.t_folders(id),
6
-  name text
7
-);
8
-
9 3
 create table macarrodes.t_bookmarks (
10 4
   id serial primary key,
11 5
   title text,
@@ -17,22 +11,21 @@ create table macarrodes.t_bookmarks (
17 11
   len integer,
18 12
   lan text,
19 13
   nclicks integer default 0,
20
-  notes text,
21
-  folder integer references macarrodes.t_folders
14
+  notes text
22 15
 );
23 16
 
24 17
 create table macarrodes.t_tags (
25 18
   id serial primary key,
26 19
   name text unique,
27
-  stem text unique,
28
-  special boolean default false
20
+  stem text unique
29 21
 );
30 22
 
31
-insert into macarrodes.t_tags (name, special) values 
32
-    ('Read it later', true),
33
-    ('Favorite', true),
34
-    ('In initial page', true),
35
-    ('Useful', false);
23
+create table macarrodes.t_folders (
24
+  id serial primary key,
25
+  tag integer references macarrodes.t_tags(id),
26
+  folder_order integer default 0,
27
+  folder_type text default ''
28
+);
36 29
 
37 30
 create table macarrodes.t_bookmarks_tags (
38 31
   bookmark integer references macarrodes.t_bookmarks,
@@ -44,18 +37,19 @@ create view macarrodes.tags as
44 37
     t_tags.id,
45 38
     t_tags.stem,
46 39
     t_tags.name,
47
-    t_tags.special,
40
+    count(t_folders.id) > 0 as special,
48 41
     count(t_bookmarks_tags.tag) as bookmarks_count
49 42
   from 
50 43
     macarrodes.t_tags
51 44
   left join macarrodes.t_bookmarks_tags on
52 45
     t_bookmarks_tags.tag = macarrodes.t_tags.id
46
+  left join macarrodes.t_folders on 
47
+    macarrodes.t_folders.tag = t_tags.id
53 48
   group by
54 49
     t_tags.id
55 50
   ;
56 51
 
57
-create type inner_value as (id integer, name text);
58
-create type inner_value_2 as (id integer, stem text, name text, special boolean, bookmarks_count integer);
52
+create type inner_value as (id integer, stem text, name text, special boolean, bookmarks_count integer);
59 53
 create view macarrodes.bookmarks as
60 54
   select 
61 55
     t_bookmarks.id,
@@ -69,13 +63,9 @@ create view macarrodes.bookmarks as
69 63
     t_bookmarks.len,
70 64
     t_bookmarks.lan,
71 65
     t_bookmarks.notes,
72
-    case 
73
-      when t_bookmarks.folder is null then null
74
-      else ROW(t_bookmarks.folder, t_folders.name)::inner_value 
75
-    end as folder,
76 66
     array(
77 67
       select 
78
-        row(macarrodes.tags.id, macarrodes.tags.stem, macarrodes.tags.name, macarrodes.tags.special, macarrodes.tags.bookmarks_count)::inner_value_2
68
+        row(macarrodes.tags.id, macarrodes.tags.stem, macarrodes.tags.name, macarrodes.tags.special, macarrodes.tags.bookmarks_count)::inner_value
79 69
       from
80 70
         macarrodes.tags, macarrodes.t_bookmarks_tags
81 71
       where 
@@ -93,35 +83,12 @@ create view macarrodes.bookmarks as
93 83
     ), 1) as tags_count /* FIXME: This subquery repeats the previous field process; it should take the previous one and not re-do it */
94 84
   from 
95 85
     macarrodes.t_bookmarks
96
-  left join macarrodes.t_folders on
97
-    t_bookmarks.folder = t_folders.id
98
-  ;
99
-
100
-create view macarrodes.folders as
101
-  select 
102
-    t_folders.id,
103
-    t_folders.name,
104
-    case 
105
-      when t_folders.parent is null then null
106
-      else ROW(t_folders.parent, t_folders_parent.name)::inner_value
107
-    end as parent,
108
-    count(t_bookmarks.id) as bookmarks_count
109
-  from 
110
-    macarrodes.t_folders
111
-  left join macarrodes.t_folders as t_folders_parent on
112
-    t_folders_parent.id = macarrodes.t_folders.parent
113
-  inner join macarrodes.t_bookmarks on
114
-    t_bookmarks.folder = t_folders.id
115
-  group by 
116
-    t_folders.id,
117
-    t_folders_parent.id
118 86
   ;
119 87
 
120 88
 create role anonymous nologin;
121 89
 grant anonymous to postgres;
122 90
 grant usage on schema macarrodes to anonymous;
123 91
 grant select on macarrodes.bookmarks to anonymous;
124
-grant select on macarrodes.folders to anonymous;
125 92
 grant select on macarrodes.tags to anonymous;
126 93
 grant insert, update on macarrodes.t_tags to anonymous;
127 94
 
@@ -130,4 +97,4 @@ GRANT ALL PRIVILEGES ON TABLE macarrodes.t_bookmarks TO anonymous;
130 97
 GRANT USAGE, SELECT ON SEQUENCE macarrodes.t_bookmarks_id_seq TO anonymous;
131 98
 GRANT ALL PRIVILEGES ON TABLE macarrodes.t_tags TO anonymous; 
132 99
 GRANT USAGE, SELECT ON SEQUENCE macarrodes.t_tags_id_seq TO anonymous;
133
-GRANT ALL PRIVILEGES ON TABLE macarrodes.t_bookmarks_tags TO anonymous; 
100
+GRANT ALL PRIVILEGES ON TABLE macarrodes.t_bookmarks_tags TO anonymous; 

+ 1
- 1
src/App.vue View File

@@ -10,7 +10,7 @@
10 10
           <li :class="{'is-active': sectionActive === 'frontpage'}" @click="sectionActive='frontpage'"><a>Frontpage</a></li>
11 11
           <li :class="{'is-active': sectionActive === 'explore'}" @click="sectionActive='explore'"><a>Explore</a></li>
12 12
           <li :class="{'is-active': sectionActive === 'tags'}" @click="sectionActive='tags'"><a>Tags</a></li>
13
-          <li :class="{'is-active': sectionActive === 'settings'}" @click="sectionActive='settings'"><a>Settings</a></li>
13
+          <li :class="{'is-active': sectionActive === 'customize'}" @click="sectionActive='customize'"><a>Customize</a></li>
14 14
         </ul>
15 15
       </div>
16 16
     </div>

Loading…
Cancel
Save