Answers.Body: <p>I happen to be doing this in an extension at the moment... I had the table created normally and stuck</p>
  
  <pre><code>  // Make sure the log table is created if required
    $schema = new CRM_Logging_Schema();
    $schema-&gt;fixSchemaDifferences();
  </code></pre>
  
  <p>at the end of the civicrm_enable hook. Unless I take care of this, if I install the extension with logging already enabled and try to create one of my new entity with drush right away, I get an error about the log table not existing.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-21T14:59:10.697Z
Answers.LastActivityDate: 2015-08-21T14:59:10.697Z
Answers.UserDisplayName: DaveFF
Answers.Body: <p>Per Lobo's comment - the logging triggers &amp; tables are automatically created. But, from experience sometimes you have to turn logging off &amp; on to get the tables created. The triggers seem to create &amp; cause lots of errors which stop when you turn logging off &amp; on. </p>
  
  <p>Obviously the function called by turning logging on is more thorough than the enable extension function</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-04T04:26:39.300Z
Answers.LastActivityDate: 2015-05-04T04:26:39.300Z
Answers.UserDisplayName: eileen
Answers.Body: <p>All tables that start with "civicrm_" are logged. tables with _temp and _cache in their names are skipped (and a few other tables).</p>
  
  <p>You can check the code at CRM/Logging/Schema.php</p>
  
  <p>Might be good to consider using hook(s) in multiple places so extensions can add to the list of tables to be logged and excluded</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-04T03:01:25.473Z
Answers.LastActivityDate: 2015-05-04T03:01:25.473Z
Answers.UserDisplayName: Donald Lobo
Body: <p>In an extension, what is the best way to create a DB table that has a matching logging table? Do we just have to literally create a matching new table with triggers? </p>
  
  <p>There must be a better way?</p>
  
Tags: <database>
Title: Best way to create a new DB table in an extension with logging
ThreadText: # Best way to create a new DB table in an extension with logging
  
  (Asked by: username_0 on 2015-05-03)
  
  In an extension, what is the best way to create a DB table that has a matching logging table? Do we just have to literally create a matching new table with triggers?
  
  There must be a better way?
  
  **Tags:** database
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2015-08-21. Score: 1 | Accepted answer
  
  I happen to be doing this in an extension at the moment... I had the table created normally and stuck
  
  ```
    // Make sure the log table is created if required
    $schema = new CRM_Logging_Schema();
    $schema->fixSchemaDifferences();
  
  ```
  
  at the end of the civicrm\_enable hook. Unless I take care of this, if I install the extension with logging already enabled and try to create one of my new entity with drush right away, I get an error about the log table not existing.
  
  
  ---
  
  ### Answer by username_2 on 2015-05-04. Score: 3
  
  Per username_3's comment - the logging triggers & tables are automatically created. But, from experience sometimes you have to turn logging off & on to get the tables created. The triggers seem to create & cause lots of errors which stop when you turn logging off & on.
  
  Obviously the function called by turning logging on is more thorough than the enable extension function
  
  
  ---
  
  ### Answer by username_3 on 2015-05-04. Score: 1
  
  All tables that start with "civicrm\_" are logged. tables with \_temp and \_cache in their names are skipped (and a few other tables).
  
  You can check the code at CRM/Logging/Schema.php
  
  Might be good to consider using hook(s) in multiple places so extensions can add to the list of tables to be logged and excluded
  
  
  ---
  
  