Documentation

Create ext_tables.sql file

Or copy link

Create ext_tables.sql file

Estimated reading: minutes 3 views

3 views
Min read

1. Define the sql structure in ext_tables.sql file

2. File path should be employee/ ext_tables.sql (it should be extension_key_name_folder/ext_tables.sql)

3. This file should contain a table-structure dump of the tables used by the extension which are not auto-generated. 

4. It is used for evaluation of the database structure and is applied to the database when an extension is enabled.

5. If you add additional fields (or depend on certain fields) to existing tables you can also put them here.

6. In this case insert a CREATE TABLE structure for that table, but remove all lines except the one defining the fields you need. 

7. TYPO3 will merge this table definition to the existing table definition when comparing expected and actual table definitions.

8. The database schema analyzer automatically creates TYPO3 “management”-related database columns by reading a table’s TCA and checking the Table properties (ctrl) section for table capabilities.

9. These columns below are automatically added if not defined in ext_tables.sql for database tables that provide a $GLOBALS[‘TCA’] definition:

  1. uid : If the uid field is not provided inside the ext_tables.sql file, the PRIMARY KEY constraint must be omitted, too.
  2. pid : The column pid is unsigned, if the table is not workspace-aware, the default index parent includes pid and hidden as well as deleted, if the latter two are specified in TCA’s Table properties (ctrl). 
  3. tstamp : Often set to tstamp or updatedon.
  4. crdate  :Often set to crdate or createdon.
  5. delete : Often set to deleted.
  6. disabled : Often set to hidden or disabled.
  7. starttime : Often set to starttime.
  8. endtime : Often set to endtime.
  9. fe_group : Often set to fe_group.
  10. sortby : Often set to sorting.
  11. descriptionColumn : Often set to description.
  12. editlock : Often set to editlock.
  13. languageField : Often set to sys_language_uid.
  14. transOrigPointerField: Often set to l10n_parent.
  15. translationSource : Often set to l10n_source.
  16. l10n_state : Column added if [‘ctrl’][‘languageField’] and [‘ctrl’][‘transOrigPointerField’] are set.
  17. origUid : Often set to t3_origuid.
  18. transOrigDiffSourceField : Often set to l10n_diffsource.

10. Let’s create ext_tables.sql file.

11. Define table with create table query.

12. Table name pattern should be tx_extensionkey_domain_model_<tablename>

13. Here in this example the table is tx_employee_domain_model_employ

14. Define the employ table like this:

CREATE TABLE tx_employee_domain_model_employ (
first_name varchar(255) DEFAULT '' NOT NULL,
last_name varchar(255) DEFAULT '' NOT NULL,
gender int(11) DEFAULT 0 NOT NULL,
birth_date int(11) DEFAULT '0' NOT NULL,
joining_date int(11) DEFAULT '0' NOT NULL,
image int(11) unsigned DEFAULT '0',
bio text,
experiance text,
salary double(11,2) DEFAULT 0.00 NOT NULL,
languages int(11) DEFAULT 0 NOT NULL,
country tinytext,
);

15. Also define the table for education

CREATE TABLE tx_employee_domain_model_education (
title varchar(255) DEFAULT '' NOT NULL,
rollnumber varchar(255) DEFAULT '' NOT NULL,
start_date int(11) DEFAULT '0' NOT NULL,
end_date int(11) DEFAULT '0' NOT NULL,
cgpa double(11,2) DEFAULT 0.00 NOT NULL,
university tinytext,
);

After saving this file, please toggle the extension (Deactivate once and then activate again) or go to Maintainance > Flush TYPO3 and PHP cache and click on the button “Flush cache” and then you will get the tables you have created.

16. Still the autogenerated fields are not added in tables as defined above, because the TCA files are yet not defined.

17. Let’s create the TCA files

Share

Leave a Comment