Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer
    
Yes @tenken my fault, I made a wrong assumption. Schema is what I need. Thanks. –  drcelus Jan 18 '13 at 7:00
add comment

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.

http://drupal.org/project/schema

share|improve this answer
    
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 '13 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 '13 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 '13 at 7:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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