I have a, rather big, application that I would like to integrate into Drupal reusing the current database design / logic.

Is there a tool out there that can help me to build the PHP part of the hook_schema definition taking the current database model or an SQL file with the DB declaration as a starting point ?

From what I know it should be pretty trivial to convert a SQL file to a PHPish definition compatible with drupal.

The utility should convert SQL types to Drupal types and declare primary keys, unique keys and index ala drupal.

2 Answers 2


I knew of a few possabilities, only 2 may work. I haven't tried:

dbtng_migrator - migrates a drupal db to different DBMS engines at will. no schema export support.

Data - module to move data into and out of drupal databases.

The Data module provides

an API for dynamically allocating tables for single-row records. an API for insert/update/delete operations and describing how tables join to each other. automatic views integration. a way to export table definitions to code.

Schema - drush dl schema Includes the following functionality not found in Core:

Schema structure generation: the module examines the live database and creates Schema API data structures for all tables that match the live database.

I have a drupal DB with other database connections defined in settings.php. You can go into Schema settings and tell to look at any named database connection (by default drupal is default). Here I select dew_remote_sources -- a "remote" (non drupal) database of data. The inspect tab then lists the SchemaAPI hook_schema defintion for each table with dummy comments to fillin. switch schema to inspect a db connection sample stubbed out schema defintion from sql structure

Lastly views_schema is pretty cool. It creates the hook_views_data for drupal tables based on their schema api definition.

Honestly I dont think you looked at @4Life answer close enough because given a db connection string, Schema does what you want.

  • Yes @tenken my fault, I made a wrong assumption. Schema is what I need. Thanks.
    – drcelus
    Jan 18, 2013 at 7:00
  • 1
    The Schema module did the trick for my use case. Sep 27, 2017 at 21:29

Have you tried the schema module.

The Schema API allows modules to declare their database tables in a structured array (similar to the Form API) and provides API functions for creating, dropping, and changing tables, columns, keys, and indexes.


  • I already knew about this module, but what I want to achieve is quite different. I would like to convert my already designed database (for example from a sql script) to add the table definitions to drupal using hook_schema.
    – drcelus
    Jan 17, 2013 at 15:43
  • 1
    it helps to do some research into how to use the modules people suggest. if you have a live instance of your DB from a mysql schema/dumpfile, then Schema can do this. dont just downvote blindly because you thnk you know everything a module does.
    – tenken
    Jan 17, 2013 at 16:20
  • @4life that was a stupid downvote by me, if you edit your answer I will be able to remove it. Sorry about that.
    – drcelus
    Jan 18, 2013 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.