To avoid incurring in overhead on every request you could use a script to be called once with web2py.py -R option. Also you could create a function in a model file with little overhead:
def create_indexes(): db.executesql('CREATE INDEX...') .... later you can call it manually from the shell env (web2py -M -S <app> ) 2016-07-11 17:38 GMT+02:00 黄祥 <steve.van.chris...@gmail.com>: > yes, you have a nice trick on your code, thanks so much massimo > e.g. > # -*- coding: utf-8 -*- > > # index > def index(): > filename = os.path.join(request.folder, 'databases', 'idx_tables.index') > if not os.path.exists(filename): > # create index : auth_user > db.executesql('CREATE INDEX idx_auth_user ON auth_user (id, first_name, > last_name, email, username);') > > # create index : auth_group > db.executesql('CREATE INDEX idx_auth_group ON auth_group (id, role);') > > # create file index in databases folder > open(filename, 'w').write(datetime.datetime.now().isoformat() ) > > if db(db.add_group).isempty() and db(db.auth_user).isempty(): > # group > auth.add_group('Admin', 'Admin') > # user > db.auth_user.bulk_insert([ > {"first_name" : "Admin", "last_name" : "Admin", > "email" : "a...@a.com", "username" : "admin", > "password" : db.auth_user.password.validate("password")[0] }, ] ) > > session.flash = T('Installation Done') > redirect(URL('default', 'index') ) > > best regards, > stifan > > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.