NAME
OpenResty::Spec::MetaModel - Metamodel for OpenResty backends
VERSION
This document describes the 0.02 version of the metamodel used in the OpenResty 0.2.x series.
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.
Global metamodel
The global metamodel stores the global (system-wide) information about the OpenResty users.
It sits in a separate PostgreSQL schema named _admin. It owns the following meta tables:
- _version
-
The definition of the
_versiontable iscreate table _version ( version varchar(10) )Usually it stores the version 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.2.x series uses metamodel 0.02 while the versions earlier uses 0.01 instead. This table usually has only 1 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 current user schema.
- _accounts
-
The
_accountstable 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, created_on timestamp (0) with time zone )The
namecolumn specifies the name of the account while thecreated_onis the creation time of the account.
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 carrie has a corresponding database schema (or namespace) named carrie. The carrie schema has the following meta tables:
- _version
-
The definition of the _version table is
create table _version ( version varchar(10) )It is exactly the same as the _version table in the global metamodel.
- _roles
-
The
_rolestable 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 );The
logincolumn specifies the login method used by the role. Allowed values are'password','anonymous', and'captcha'.The
passwordcolumn must be not null when thelogincolumn has the value of'password'. Its values should be null otherwise. - _access
-
The
_accesstable 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, url text not null );The
rolecolumn 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
methodandurl, respectively. An example is thatmethodhas a value of'GET'andurlhas a value of'/=/model/~/~/~'. - _models
-
The
_modelstable stores the meta information regarding the OpenResty models.The definition of _models is
create table _models ( id serial primary key, name text unique not null, description text not null );The
namecolumn stores the names of user models. Every user model is represented by a physical PostgreSQL table under the same schema and the leading character of its name must be case-sensitive letters. Table names leading by an underscore are preserved for meta tables.The
descriptioncolumn stores users' textual description for their models.Neither
namenordescriptioncan be null. - _columns
-
The
_columnstable stores the meta information regarding OpenResty models' columns.create table _columns ( id serial primary key, name text not null, model text not null, label text not null, type text not null, default_value text, indexed text, unique(model, name) );The
namecolumn keeps the names of user models' columns and themodelcolumn stores the names of the corresponding models.The
lablecolumn stores the textual label provided by the user who created the column and types of the model columns are stored in thetypecolumn.None of the columns above but
default_valueandindexedcan be null and in addition, the combination of the columnsmodelandnameshould be unique.User columns have default values and the corresponding JSON representation is stored in the
default_valuecolumn. Note that the values fordefault_valueare JSON literals, for instance,"32",["now()"], and etc.The
indexedcolumn stores the index method applied to the current user column if any; null otherwise. Possible values are 'fulltext', 'btree', 'rtree', 'gist', and 'hash'. - _views
-
The
_viewstable stores the information of the OpenResty View objects.create table _views ( id serial primary key, name text unique not null, definition text unique not null, description text );All of the columns have similar meaning as the
_modeltable except that thedefinitioncolumn stores the minisql string defining the functionality of the view. - _actions
-
The
_actionstable stores the information of the OpenResty Action objects.create table _action ( id serial primary key, name text unique not null, description text, definition text unique not null, confirmed_by text );Most of the columns are similar to those in the
_viewtable except that the lastconfirmed_bycolumn specifies the confirmation method used to fire the action. Allowed values for this column are "email", "cellphone", and "captcha". - _feeds
-
WARNING This part deserves more treatment.
The
_feedstable 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, arguments text not null, type text not null, snapshot text );The
argumentscolumn defines the mapping from Feed entries' attributes to the associated View object's columns. The JSON representation is used as theargumentscolumn's value. An example for the case of Atom/RSS feed is:{title:"title",author:"poster",link:"http://blog.agentzh.org/#post-$id",issued:"created",summary:"content",summary_type:"html"}For email feeds, it may look like
{title:"title",body:"content",body_type:"html"}The
typecolumn specifies the type of the Feed object, like "RSS 0.9", "RSS 1.0", "RSS 2.0", "Atom", and "email".The snapshot stores a snapshot of the feeds which are usually automatically updated by OpenResty deamon processes.
AUTHOR
agentzh <agentzh@yahoo.cn>
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