docker + Umami + Postgresql 网站访问分析

 1 # docker + Umami + Postgresql
 2 # 官方安装文档:https://umami.is/docs/install
 3 # 一、创建数据库
 4 #    1.创建用户
 5      CREATE ROLE umami PASSWORD 'xxx' login;
 6 #    2.创建数据库
 7      create database umami_db;
 8 #    3.修改数据库的拥有者
 9      alter database umami_db owner to "umami";
10 #    4.创建数据库表-如果你想从官方下载的话就得克隆(博客后面会提供sql窗表语句)
11      先克隆:git clone https://github.com/mikecao/umami.git
12      创建表sql语句文件路劲在:umami/sql/schema.postgresql.sql
13      执行语句:psql -h locahost -p 5432 -d umami_db -U umami -W -f ~/umami/sql/schema.postgresql.sql
14 #    5.数据库的URL
15      postgresql://umami:xxx@localhost:5432/umami_db
16 # 二、运行docker
17 docker container run --name umami-odoo -p 3000:3000 -e DATABASE_URL="postgresql://umami:xxx@localhost:5432/umami_db" -e DATABASE_TYPE="postgresql" -d ghcr.io/mikecao/umami:postgresql-latest
18 # 三、访问http://localhost:3000
19 #    1.进入设置界面
20 #    2.添加你的网站(共享勾上)
21 #    3.然后生成的网站记录右边有几个按钮,点击“获取跟踪代码”
22 #    4.将跟踪代码复制到你的网站的head元素里就行(这就查看网站的点击量了)
23 #    5.再点击“获取共享链接”,那就可以吧网站分析的内容显示在你的网站里边了
24      <iframe style="width: 100%; height: 1200px;" scrolling="no" frameborder="0" src="http://localhost:3000/share/79eDmaOf/test"></iframe>

 

创建表的语句

drop table if exists event;
drop table if exists pageview;
drop table if exists session;
drop table if exists website;
drop table if exists account;

create table account (
    user_id serial primary key,
    username varchar(255) unique not null,
    password varchar(60) not null,
    is_admin bool not null default false,
    created_at timestamp with time zone default current_timestamp,
    updated_at timestamp with time zone default current_timestamp
);

create table website (
    website_id serial primary key,
    website_uuid uuid unique not null,
    user_id int not null references account(user_id) on delete cascade,
    name varchar(100) not null,
    domain varchar(500),
    share_id varchar(64) unique,
    created_at timestamp with time zone default current_timestamp
);

create table session (
    session_id serial primary key,
    session_uuid uuid unique not null,
    website_id int not null references website(website_id) on delete cascade,
    created_at timestamp with time zone default current_timestamp,
    hostname varchar(100),
    browser varchar(20),
    os varchar(20),
    device varchar(20),
    screen varchar(11),
    language varchar(35),
    country char(2)
);

create table pageview (
    view_id serial primary key,
    website_id int not null references website(website_id) on delete cascade,
    session_id int not null references session(session_id) on delete cascade,
    created_at timestamp with time zone default current_timestamp,
    url varchar(500) not null,
    referrer varchar(500)
);

create table event (
    event_id serial primary key,
    website_id int not null references website(website_id) on delete cascade,
    session_id int not null references session(session_id) on delete cascade,
    created_at timestamp with time zone default current_timestamp,
    url varchar(500) not null,
    event_type varchar(50) not null,
    event_value varchar(50) not null
);

create index website_user_id_idx on website(user_id);

create index session_created_at_idx on session(created_at);
create index session_website_id_idx on session(website_id);

create index pageview_created_at_idx on pageview(created_at);
create index pageview_website_id_idx on pageview(website_id);
create index pageview_session_id_idx on pageview(session_id);
create index pageview_website_id_created_at_idx on pageview(website_id, created_at);
create index pageview_website_id_session_id_created_at_idx on pageview(website_id, session_id, created_at);

create index event_created_at_idx on event(created_at);
create index event_website_id_idx on event(website_id);
create index event_session_id_idx on event(session_id);

insert into account (username, password, is_admin) values ('admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa', true);

 

posted @ 2022-04-25 08:56  看一百次夜空里的深蓝  阅读(425)  评论(0)    收藏  举报