Ticket #7203 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

Set up database on environment_create()

Reported by: pipern Assigned to: mrelbe
Priority: normal Component: TracTicketChangesetsPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description

I think it's nice to avoid an upgrade step if the plugin is enabled when the environment is first created, so I did this:

--- a/ticketchangesets/init.py
+++ b/ticketchangesets/init.py
@@ -36,7 +36,12 @@ class TicketChangesetsInit(Component):
 
     # IEnvironmentSetupParticipant.
     def environment_created(self):
-        pass
+        """ Called when a new environment is created. Procedure is similar to
+        an environment upgrade, but we also need to commit the changes
+        ourselves. """
+        db = self.env.get_db_cnx()
+        self.upgrade_environment(db)
+        db.commit()
 
     def environment_needs_upgrade(self, db):
         # Is database up to date?

Attachments

Change History

06/05/10 01:44:50 changed by mrelbe

  • status changed from new to assigned.

If you create an environment from scratch, this plugin cannot be activated. Therefore, the only use case must be when an environment is created with the "--inherit" option. Right?

But the problem is that something goes terribly wrong when I try this with Trac 0.12dev-r9818.

The provided patch is nevertheless a good suggestion, I'll get back when I found the problem with creating inherited environments.

06/06/10 11:56:55 changed by mrelbe

The problem was me ;) I'm going to apply the patch now.

06/06/10 12:32:02 changed by mrelbe

I think the patch should look like this:

--- ticketchangesets/init.py	(revision 8072)
+++ ticketchangesets/init.py	(working copy)
@@ -36,7 +36,10 @@
 
     # IEnvironmentSetupParticipant.
     def environment_created(self):
-        pass
+        """Initialise a created environment for this plugin."""
+        @self.env.with_transaction()
+        def do_create(db):
+            self.upgrade_environment(db)
 
     def environment_needs_upgrade(self, db):
         # Is database up to date?

BUT: How can the plugin be activated during the creation of an environment? I cannot verify this code...

06/09/10 20:18:20 changed by anonymous

#T9416 explains the problem, I will fix this when that is fixed first.

06/11/10 14:02:20 changed by mrelbe

[T9847] makes it possible to test this.

06/11/10 14:05:56 changed by mrelbe

  • status changed from assigned to closed.
  • type changed from defect to enhancement.
  • resolution set to fixed.

Fix committed in [8111].


Add/Change #7203 (Set up database on environment_create())




Change Properties
Action