X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=mysql.sql;h=ad4516b1fc444b12a1a376b41308f5af729dcc67;hb=7993ce63bc6a4249ab508c3bbf4fb7ec5be1b9a3;hp=3c52aefc439371e80256789c7c3dcd150590f078;hpb=73d14da2b2bf18a91937cf08ee3da6e62f2d01e0;p=timetracker.git diff --git a/mysql.sql b/mysql.sql index 3c52aefc..ad4516b1 100644 --- a/mysql.sql +++ b/mysql.sql @@ -14,7 +14,7 @@ # CREATE TABLE `tt_teams` ( `id` int(11) NOT NULL auto_increment, # team id - `timestamp` timestamp default CURRENT_TIMESTAMP, # modification timestamp + `timestamp` timestamp default CURRENT_TIMESTAMP, # Modification timestamp. TODO: redo all timestamps to survive beyond 2038. `name` varchar(80) default NULL, # team name `currency` varchar(7) default NULL, # team currency symbol `decimal_mark` char(1) NOT NULL default '.', # separator in decimals @@ -38,6 +38,37 @@ CREATE TABLE `tt_teams` ( ); +# +# Structure for table tt_roles. This table stores customized team roles. +# +CREATE TABLE `tt_roles` ( + `id` int(11) NOT NULL auto_increment, # Role id. Identifies roles for all groups on the server. + `team_id` int(11) NOT NULL, # Team id the role is defined for. + `name` varchar(80) default NULL, # Role name - custom role name. In case we are editing a + # predefined role (USER, etc.), we can rename the role here. + `description` varchar(255) default NULL, # Role description. + `rank` int(11) default 0, # Role rank, an integer value between 0-324. Predefined role ranks: + # USER - 4, CLIENT - 16, COMANAGER - 68, MANAGER - 324. + # Rank is used to determine what "lesser roles" are in each group + # for sutuations such as "manage_users". + # It also identifies a role within a team (by its "rank"). + # Value of rank is to be used in role field in tt_users table, + # just like standard roles now. + `rights` text default NULL, # Comma-separated list of rights assigned to a role. + # NULL here for predefined roles (4, 16, 68, 324 - manager) + # means a hard-coded set of default access rights. + `status` tinyint(4) default 1, # Role status. + PRIMARY KEY (`id`) +); + +# Create an index that guarantees unique active and inactive role ranks in each group. +create unique index role_idx on tt_roles(team_id, rank, status); + +# Insert site-wide roles - site administrator and top manager. +INSERT INTO `tt_roles` (`team_id`, `name`, `rank`, `rights`) VALUES (0, 'Site administrator', 1024, 'administer_site'); +INSERT INTO `tt_roles` (`team_id`, `name`, `rank`, `rights`) VALUES (0, 'Top manager', 512, 'track_own_time,track_own_expenses,view_own_reports,view_own_charts,view_own_invoices,manage_own_settings,view_users,track_time,track_expenses,view_reports,view_charts,override_punch_mode,override_own_punch_mode,override_date_lock,override_own_date_lock,swap_roles,approve_timesheets,manage_users,manage_projects,manage_tasks,manage_custom_fields,manage_clients,manage_invoices,manage_features,manage_basic_settings,manage_advanced_settings,manage_roles,export_data,manage_subgroups'); + + # # Structure for table tt_users. This table is used to store user properties. # @@ -48,10 +79,18 @@ CREATE TABLE `tt_users` ( `password` varchar(50) default NULL, # password hash `name` varchar(100) default NULL, # user name `team_id` int(11) NOT NULL, # team id - `role` int(11) default 4, # user role ("manager", "co-manager", "client", or "user") + `role_id` int(11) default NULL, # role id `client_id` int(11) default NULL, # client id for "client" user role `rate` float(6,2) NOT NULL default '0.00', # default hourly rate `email` varchar(100) default NULL, # user email + `created` datetime default NULL, # creation timestamp + `created_ip` varchar(45) default NULL, # creator ip + `created_by` int(11) default NULL, # creator user_id (null for self) + `modified` datetime default NULL, # modification timestamp + `modified_ip` varchar(45) default NULL, # modifier ip + `modified_by` int(11) default NULL, # modifier user_id + `accessed` datetime default NULL, # last access timestamp + `accessed_ip` varchar(45) default NULL, # last access ip `status` tinyint(4) default 1, # user status PRIMARY KEY (`id`) ); @@ -61,7 +100,7 @@ create unique index login_idx on tt_users(login, status); # Create admin account with password 'secret'. Admin is a superuser, who can create teams. DELETE from `tt_users` WHERE login = 'admin'; -INSERT INTO `tt_users` (`login`, `password`, `name`, `team_id`, `role`) VALUES ('admin', md5('secret'), 'Admin', '0', '1024'); +INSERT INTO `tt_users` (`login`, `password`, `name`, `team_id`, `role_id`) VALUES ('admin', md5('secret'), 'Admin', '0', (select id from tt_roles where rank = 1024)); # @@ -144,6 +183,12 @@ CREATE TABLE `tt_log` ( `comment` text, # user provided comment for time record `billable` tinyint(4) default 0, # whether the record is billable or not `paid` tinyint(4) default 0, # whether the record is paid + `created` datetime default NULL, # creation timestamp + `created_ip` varchar(45) default NULL, # creator ip + `created_by` int(11) default NULL, # creator user_id + `modified` datetime default NULL, # modification timestamp + `modified_ip` varchar(45) default NULL, # modifier ip + `modified_by` int(11) default NULL, # modifier user_id `status` tinyint(4) default 1, # time record status PRIMARY KEY (`id`) ); @@ -383,21 +428,16 @@ ALTER TABLE `tt_monthly_quotas` # -# Structure for table tt_roles. This table stores customized team roles. +# Structure for table tt_site_config. This table stores configuration data +# for Time Tracker site as a whole. +# For example, database version, code version, site language, etc. # -CREATE TABLE `tt_roles` ( - `id` int(11) NOT NULL auto_increment, # role id - `team_id` int(11) NOT NULL, # team id - `name` varchar(80) default NULL, # role name - may be used to rename standard roles - `rank` int(11) default 0, # Role rank and identifier in comparison with other roles, - # used to determine what "lesser roles" are - # and also identifies a role within a team, used as role in tt_users. - `rights` text default NULL, # Comma-separated list of rights assigned to a role. - # NULL here for predefined roles (4, 16, 68, 324 - manager) - # means a hard-coded set of default access rights. - `status` tinyint(4) default 1, # role status - PRIMARY KEY (`id`) +CREATE TABLE `tt_site_config` ( + `param_name` varchar(32) NOT NULL, # parameter name + `param_value` text default NULL, # parameter value + `created` datetime default NULL, # creation timestamp + `modified` datetime default NULL, # modification timestamp + PRIMARY KEY (`param_name`) ); -# Create an index that guarantees unique active and inactive role ranks per team. -create unique index role_idx on tt_roles(team_id, rank, status); +INSERT INTO `tt_site_config` (`param_name`, `param_value`, `created`) VALUES ('version_db', '1.17.56', now()); # TODO: change when structure changes.