Warn
POD ERRORS here is normal because DBIx::POS::Template used.
Mojolicious::Plugin::RoutesAuthDBI::Install
¡ ¡ ¡ ALL GLORY TO GLORIA ! ! !
NAME
Mojolicious::Plugin::RoutesAuthDBI::Install - is a Mojolicious::Controller for installation instructions. DB schema (PostgreSQL) and sample app.
DB DESIGN DIAGRAM
See https://github.com/mche/Mojolicious-Plugin-RoutesAuthDBI/blob/master/Diagram.svg
Manual
$ perl -e "use Mojo::Base 'Mojolicious'; __PACKAGE__->new()->start(); sub startup {shift->routes->route('/')->to('install#manual', namespace=>'Mojolicious::Plugin::RoutesAuthDBI');}" get / 2>/dev/null
DB schema (postgresql)
View schema (define the postgresql schema name)
$ perl -e "use Mojo::Base 'Mojolicious'; __PACKAGE__->new()->start(); sub startup {shift->routes->route('/schema/:schema')->to('install#schema', namespace=>'Mojolicious::Plugin::RoutesAuthDBI');}" get /schema/<name> 2>/dev/null # get /schema/foo || get /schema/public
Apply schema (define the postgresql schema name)
$ perl -e "use Mojo::Base 'Mojolicious'; __PACKAGE__->new()->start(); sub startup {shift->routes->route('/schema/:schema')->to('install#schema', namespace=>'Mojolicious::Plugin::RoutesAuthDBI');}" get /schema/<name> 2>/dev/null | psql -d <dbname> # get /schema/foo || get /schema/public
Sample app
$ perl -e "use Mojo::Base 'Mojolicious'; __PACKAGE__->new()->start(); sub startup {shift->routes->route('/')->to('install#test_app', namespace=>'Mojolicious::Plugin::RoutesAuthDBI');}" get / 2>/dev/null > test-app.pl
use Mojo::Base 'Mojolicious';
use DBI;
has dbh => sub { DBI->connect("DBI:Pg:dbname=<dbname>;", "postgres", undef); };
sub startup {
my $app = shift;
# $app->plugin(Config =>{file => 'Config.pm'});
$app->plugin('RoutesAuthDBI',
dbh=>$app->dbh,
auth=>{current_user_fn=>'auth_user'},
# access=> {},
admin=>{prefix=>'myadmin', trust=>'fooobaaar',},
);
}
__PACKAGE__->new()->start();
--
Define DBI->connect(.........) and some plugin options in test-app.pl
Check list of admin routes:
$ perl test-app.pl routes
Start app
$ perl test-app.pl daemon
Trust url for admin-user creation:
$ perl test-app.pl get /<pluginconf->{admin}{prefix}>/<pluginconf->{admin}{trust}>/user/new/<new admin login>/<admin pass> 2>/dev/null
Sign in by browser:
Go to http://127.0.0.1:3000/sign/in/<new admin login>/<admin pass>
Admin index:
Go to http://127.0.0.1:3000/<pluginconf->{admin}{prefix}>
Administration of system ready!
DB design
Schema name
CREATE SCHEMA IF NOT EXISTS "{% $schema %}"; set local search_path = "{% $schema %}";
Sequence
-- you may change schema name for PostgreSQL objects CREATE SEQUENCE {% $schema %}ID;-- one sequence for all tables id
Routes
CREATE TABLE {% $schema %}routes ( id integer default nextval('{% $schema %}ID'::regclass) not null primary key, ts timestamp without time zone default now() not null, request character varying not null, name character varying not null unique, descr text null, auth varchar null,-- was bit(1): alter table {% $schema %}routes alter column auth type varchar; disable bit(1) null, -- interval_ts - смещение ts (seconds) для приоритета маршрута, т.е. влияет на сортровку маршрутов interval_ts int null -- was order_by int null; alter table {% $schema %}routes rename column order_by to interval_ts; );
Namespaces
create table {% $schema %}namespaces ( id integer default nextval('{% $schema %}ID'::regclass) not null primary key, ts timestamp without time zone default now() not null, namespace character varying not null unique, descr text null, app_ns bit(1) null, -- alter table {% $schema %}namespaces add column app_ns bit(1) null; -- interval_ts - смещение ts (seconds) для приоритета namespace interval_ts int null -- alter table {% $schema %}namespaces add column interval_ts int null; );
Controllers
create table {% $schema %}controllers ( id integer default nextval('{% $schema %}ID'::regclass) not null primary key, ts timestamp without time zone default now() not null, controller character varying not null, descr text null );
Actions
create table {% $schema %}actions ( id integer default nextval('{% $schema %}ID'::regclass) not null primary key, ts timestamp without time zone default now() not null, action character varying not null, callback text null, descr text null );
Users
create table {% $schema %}users ( id int default nextval('{% $schema %}ID'::regclass) not null primary key, ts timestamp without time zone default now() not null, login varchar not null unique, pass varchar not null, disable bit(1) );
Roles
create table {% $schema %}roles ( id int default nextval('{% $schema %}ID'::regclass) not null primary key, ts timestamp without time zone default now() not null, name varchar not null unique, disable bit(1) );
Refs
create table {% $schema %}refs ( id int default nextval('{% $schema %}ID'::regclass) not null primary key, ts timestamp without time zone default now() not null, id1 int not null, id2 int not null, unique(id1, id2) ); create index on {% $schema %}refs (id2);
Drop schema
drop table {% $schema %}refs;
drop table {% $schema %}users;
drop table {% $schema %}roles;
drop table {% $schema %}routes;
drop table {% $schema %}controllers;
drop table {% $schema %}actions;
drop table {% $schema %}namespaces;
drop sequence {% $schema %}ID;
Flush schema
delete from {% $schema %}refs;
delete from {% $schema %}users;
delete from {% $schema %}roles;
delete from {% $schema %}routes;
delete from {% $schema %}controllers;
delete from {% $schema %}namespaces;
delete from {% $schema %}actions;
36 POD Errors
The following errors were encountered while parsing the POD:
- Around line 48:
Unknown directive: =name
- Around line 50:
Unknown directive: =desc
- Around line 71:
Unknown directive: =sql
- Around line 170:
Unknown directive: =name
- Around line 172:
Unknown directive: =desc
- Around line 174:
Unknown directive: =sql
- Around line 182:
Unknown directive: =name
- Around line 184:
Unknown directive: =desc
- Around line 186:
Unknown directive: =sql
- Around line 194:
Unknown directive: =name
- Around line 196:
Unknown directive: =desc
- Around line 198:
Unknown directive: =sql
- Around line 214:
Unknown directive: =name
- Around line 216:
Unknown directive: =desc
- Around line 218:
Unknown directive: =sql
- Around line 232:
Unknown directive: =name
- Around line 234:
Unknown directive: =desc
- Around line 236:
Unknown directive: =sql
- Around line 247:
Unknown directive: =name
- Around line 249:
Unknown directive: =desc
- Around line 251:
Unknown directive: =sql
- Around line 263:
Unknown directive: =name
- Around line 265:
Unknown directive: =desc
- Around line 267:
Unknown directive: =sql
- Around line 279:
Unknown directive: =name
- Around line 281:
Unknown directive: =desc
- Around line 283:
Unknown directive: =sql
- Around line 294:
Unknown directive: =name
- Around line 296:
Unknown directive: =desc
- Around line 298:
Unknown directive: =sql
- Around line 345:
Unknown directive: =name
- Around line 347:
Unknown directive: =desc
- Around line 349:
Unknown directive: =sql
- Around line 377:
Unknown directive: =name
- Around line 379:
Unknown directive: =desc
- Around line 381:
Unknown directive: =sql