Edgewall Software
Modify

Opened 6 years ago

Closed 4 years ago

Last modified 2 years ago

#11333 closed enhancement (fixed)

TracAdmin command for DB schema

Reported by: olemis+trac@… Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2
Component: admin/console Version: 1.0.1
Severity: normal Keywords: schema initenv
Cc: ethan.jucovy@… Branch:
Release Notes:

The TracAdmin initenv command accepts an optional parameter --config, the path to a file containing a configuration to be used when creating the environment.

API Changes:

Description (last modified by Ryan J Ollos)

Offer a trac-admin command to generate DB schema (and maybe add a minimal set of rows to system table ?) . This could be useful to regenerate the database from scratch by invoking a subsequent upgrade while still keeping the rest of the environment intact . See trac-users thread for discussion .

Attachments (0)

Change History (17)

comment:1 by ethan.jucovy@…, 6 years ago

Cc: ethan.jucovy@… added

comment:2 by olemis+trac@…, 6 years ago

Considering this

$ grep -r do_initdb trac
trac/admin/console.py:    def do_initdb(self, line):
Binary file trac/admin/console.pyc matches

… and the fact that do_initdb merely forwards the invocation to do_initenv method I have replaced it's body with code submitted by Ethan Jucovy via trac-dev@… with a few minor modifications listed below .

  • Do not load default wiki pages . This may be deferred until a subsequent wiki upgrade
  • Receive DB string as an optional command line argument

To get this done the following patch should be applied .

Open question is whether this should be better implemented as a trac.env.Environment method , similar to upgrade command . If this was the case then I will submit another one aimed at implementing it in the environment instead .

In any case this patch provides test cases .

This all is still WiP but still early feedback will be appreciated .

comment:3 by olemis, 6 years ago

Patches are ready . See patches available at URLs mentioned above

$ /srv/venv/python/trac/trac-mq/bin/python trac/admin/tests/console.py
...............................................................................................................
----------------------------------------------------------------------
Ran 111 tests in 8.246s

OK

comment:4 by Olemis Lang <olemis+trac@…>, 6 years ago

These are the results after adding one more test case to check that DB config is preserved on failure and invoking DatabaseManager.shutdown as suggested by Ethan Jucovy via trac-dev@…

$ python trac/admin/tests/console.py
................................................................................................................
----------------------------------------------------------------------
Ran 112 tests in 7.436s

OK

comment:5 by saintger@…, 6 years ago

Hello,

That was a fast patch ! I tested by modifying my trac.ini database string and the database is correctly initialized with your new trac-admin command. I havent' understood why you removed the wiki load_pages, but I suppose that you had good reasons (we just have to remember loading default wiki pages after creating the database).

Thanks !

comment:6 by Ryan J Ollos, 6 years ago

Cc: Ryan J Ollos added

comment:7 by Jun Omae, 5 years ago

Keywords: initenv added; db admin cli removed
Milestone: undecided

I think you need an option to specify template trac.ini file to initenv command rather than initializing database like this.

$ trac-admin /path/to/env initenv --template=/path/to/base-env/conf/trac.ini 'Project Name' postgres:///trac

I don't think we should add the initdb command of trac-admin.

in reply to:  7 comment:8 by Ryan J Ollos, 4 years ago

Replying to jomae:

I think you need an option to specify template trac.ini file to initenv command rather than initializing database like this.

I've found myself scripting a lot of Trac installs lately that utilize a pre-existing trac.ini file (e.g. Trac upgrades with a clean install, and server migrations). The --template (or --ini) option would reduce the number of commands necessary in the script.

With a properly-coded plugin (comment:41:ticket:8172) and all plugins enabled in the template file, the environment upgrade actions would occur in environment_created and a TracAdmin upgrade would not be necessary.

Last edited 4 years ago by Ryan J Ollos (previous) (diff)

comment:9 by Ryan J Ollos, 4 years ago

Proposed changes in log:rjollos.git:t11333. I'll add more unit test coverage before committing.

comment:10 by Ryan J Ollos, 4 years ago

Milestone: undecidednext-major-releases

comment:11 by Ryan J Ollos, 4 years ago

Cc: Ryan J Ollos removed
Milestone: next-major-releases1.2
Owner: set to Ryan J Ollos
Status: newassigned

comment:12 by Ryan J Ollos, 4 years ago

Release Notes: modified (diff)

Revised changes in log:rjollos.git:t11333.2.

comment:13 by Ryan J Ollos, 4 years ago

Resolution: fixed
Status: assignedclosed

Changes committed with minor modification in [14182,14190].

Last edited 4 years ago by Ryan J Ollos (previous) (diff)

comment:14 by Jun Omae, 4 years ago

I got a failure of unit tests on Windows.

======================================================================
ERROR: test_config_argument (trac.admin.tests.console.TracAdminInitenvTestCase)
Options contained in file specified by the --config argument
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\usr\src\trac\trac.git\trac\admin\tests\console.py", line 1583, in tearDown
    shutil.rmtree(self.parent_dir)
  File "C:\usr\apps\python27-amd64\Lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\usr\apps\python27-amd64\Lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\usr\apps\python27-amd64\Lib\shutil.py", line 252, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "C:\usr\apps\python27-amd64\Lib\shutil.py", line 250, in rmtree
    os.remove(fullname)
WindowsError: [Error 32] The process cannot access the file beacause it is being used by another process.: 'c:\\users\\omae\\appdata\\local\\temp\\tmpkjwyhe\\trac\\db\\sqlite.db'

The following patch would fix it.

  • trac/admin/tests/console.py

    diff --git a/trac/admin/tests/console.py b/trac/admin/tests/console.py
    index 7a92bd2..d8ab546 100644
    a b class TracAdminInitenvTestCase(TracAdminTestCaseBase):  
    15801580        self._admin = TracAdmin(self.env_path)
    15811581
    15821582    def tearDown(self):
     1583        if os.path.isfile(os.path.join(self.env_path, 'VERSION')):
     1584            self._admin.env.shutdown()
    15831585        shutil.rmtree(self.parent_dir)
    15841586
    15851587    def test_config_argument(self):

I'll push it later.

comment:15 by Jun Omae, 4 years ago

Committed in [14217].

comment:16 by Ryan J Ollos, 3 years ago

Documented in 1.1/TracEnvironment@12.

comment:17 by Ryan J Ollos, 2 years ago

Description: modified (diff)

#12834 is related.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.