=head1 NAME OpenResty::Spec::MetaModel - Metamodel for OpenResty backends =head1 VERSION This document describes OpenResty 0.5.11's meta model, version 0.009. =head1 DESCRIPTION The metamodel in OpenResty is a set of internal database schemas or tables for storing meta information regarding the user data. They're usually invisible to the outside users and their names are carefully chosen so as to prevent potential naming conflicts with users' objects. =head1 Global metamodel The global metamodel stores the global (system-wide) information about the OpenResty users. It sits in a separate PostgreSQL schema named C<_global>. It owns the following meta tables: =over =item _general The definition of the C<_general> table is create table _general ( version varchar(10), captcha_key char(16) ) Usually it stores the version and other general information of the global metamodel itself. Note that the version of the metamodel is independent of the version number of the whole OpenResty server implementation. For instance, the OpenResty 0.1.8 uses metamodel 0.001 while the versions earlier does not have a versioned metamodel. This table usually has only one row. But it's also fine to keep track of all the version history. The largest version number will be considered the current version of the metamodel in the I user schema. The C column stores the secret key used in captcha generation, whose value must be exactly 16 bytes long and contains only characters in C<[0-9a-zA-Z]>. =item _accounts The C<_accounts> table stores the list of all the available OpenResty accounts in the whole system. It has the following definition: create table _accounts ( id serial primary key, name text unique not null, ) The C column specifies the name of the account. =back =head1 Local metamodel Each OpenResty account registered by an outside user has a PostgreSQL schema for storing its models, views, roles, actions, and other user objects. Such schema has the same name as the account name. For instance, account C has a corresponding database schema (or namespace) named C. The C schema has the following meta tables: =over =item _general The definition of the C<_general> table is create table _general ( version varchar(10), created timestamp (0) with time zone default now() ) The C column keeps the metamodel version number for the current account while the C column records its creation time. =item _roles The C<_roles> table stores the meta information of the OpenResty Role objects. create table _roles ( id serial primary key, name text unique not null, login text not null, password text, description text not null, created timestamp(0) with time zone default now() ); The C column specifies the login method used by the role. Allowed values are C<'password'>, C<'anonymous'>, and C<'captcha'>. The C column must be not null when the C column has the value of C<'password'>. Its values should be null otherwise. =item _access The C<_access> table stores the information of the access rules associated with the OpenResty Role objects. create table _access ( id serial primary key, role text not null, method varchar(10) not null, prefix text not null, segments smallint, prohibiting boolean default false not null, applied_to cidr[] default '{0.0.0.0/0}' ); The C column stores the name of the role which owns the current rule. Each access rule has two components, HTTP method and the (abbreviated) URL, which are saved in the columns C, C, and C, respectively. An example is that C has a value of C<'GET'> and C has a value of C<'/=/model/~/~/~'>. =item _views The C<_views> table stores the information of the OpenResty View objects. create table _views ( id serial primary key, description text, name text unique not null, definition text not null, created timestamp(0) with time zone default now() ); All of the columns have similar meaning as the C<_model> table except that the C column stores the minisql string defining the functionality of the view. =item _actions The C<_actions> table stores the information of the OpenResty Action objects. create table _actions ( id serial primary key, name text unique not null, definition text not null, description text, compiled text, created timestamp(0) with time zone default now() ); create table _action_params ( id serial primary key, name text not null, type text not null, label text, default_value text, used bool not null, action_id integer references _actions(id) on delete cascade ); Most of the columns are similar to those in the C<_view> table except that it takes an auxiliary table C<_action_params>. [TODO: add the C column to specify the confirmation method used to fire the action. Allowed values for this column are "email", "cellphone", and "captcha".] =item _feeds The C<_feeds> table stores the meta information for the OpenResty Feed objects. create table _feeds ( id serial primary key, name text unique not null, description text not null, view text not null, title text not null, link text not null, logo text, copyright text, language text, author text, created timestamp (0) with time zone default now() ); The C argument specifies the OpenResty view name from which the RSS/Atom feed is generated. The C, C<link>, C<logo>, C<copyright>, and C<author> are properties of the web site the current feed is referred to. =item _ylogins create table _ylogins( id serial primary key, name text unique not null, mapping_view text, on_register text not null, on_login text, next_page text not null, error_page text not null, description text, created timestamp(0) with time zone default now() ); The C<_ylogins> table merely serves our proprietary YLogin (Yahoo! Login) handler. =back =head1 HISTORY =over =item 0.008 =over =item * Left tables _models and _columns alone; no longer make use of them. =item * Added _ylogins for our closed-source YLogin (Yahoo! Login) handler. =item * Added a DB index for _access; =back =item 0.007 Added tables _actions and _action_params. =back =head1 Upgrading OpenResty supports automatic upgrading for its meta model. See L<OpenResty::Spec::Upgrading> for details. =head1 AUTHOR agentzh C<< <agentzh@yahoo.cn> >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2008 Yahoo! China EEEE Works, Alibaba Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found at L<http://www.gnu.org/licenses/fdl.html> =head1 SEE ALSO L<OpenResty::Spec::Upgrading>, L<openresty>, L<OpenResty>, L<OpenResty::Spec::Overview>.