You are here

README.txt in Schema 5

Same filename and directory in other branches
  1. 8 README.txt
  2. 6 README.txt
  3. 7 README.txt
Schema module

PREREQUISITES

Drupal 5.0

OVERVIEW

The Schema module provides Drupal with a database schema API, a method
for modules to declare their database tables in structured data rather
than via CREATE TABLE statements, and a means for Drupal to inspect
and reflect on its own database structure.

THIS MODULE IS IN PRE-ALPHA USE AT YOUR OWN RISK RELEASE!  It is
currently for demonstration, testing, and development purposes only.
You've been warned.

INSTALLATION

Install and activate Schema like every other Drupal module.

ADMINISTRATOR USAGE

As an administrator, Schema will show you information about tables
that exist in your database and how they match or do not match up with
the schema information defined by modules.  Visit Administer >> Site
building >> Schema for this information.  Note that these pages are
information-only; there are no actions you can perform from them.

*** IMPORTANT NOTE: Schema expects to find the standard Drupal tables
(declared by system.module) defined as of version 1022 (Drupal 5 head
as of April 14, 2007).  If you are using a different version of Drupal
5, it will report "mismatches" on the Report page.

MODULE DEVELOPER USAGE

Currently, don't use Schema, as everything about it is subject to
change.  

Suppose your module named mymodule wants to use a single simple table
named mytable.  Define hook_schema() in your .module file:

function mymodule_schema() {
  $schema['#version'] = 1;
  $schema['mymodule_mytable] = array(
    'name' => 'mytable',
    'cols' => array(
      'id' => array('type' => 'int', 'not null' => '1'),
      'val => array('type' => 'varchar', 'length' => 255, 'not null' => '1'),
      ),
    'keys' => array('PRIMARY' => array('id')));
  return $schema;
}

Now, in your .install file, use Schema to install and uninstall your
tables:

function schema_install() {
  $my_schema = module_invoke('mymodule, 'schema');
  schema_create_schema($my_schema);
}

function schema_uninstall() {
  $my_schema = module_invoke('mymodule, 'schema');
  schema_drop_schema($my_schema);
}

That's it!  Except, of course, this is pre-alpha code, so that
probably isn't it.
  
TO DO

- Database engines for Postgres and other DBMS's.
- The above .install code actually won't work because mymodule.module
  is not loaded when mymodule_install() is run (or is it?).
- Define join relationships, use them for world domination.

AUTHOR

Barry Jaspan
firstname at lastname dot org

File

README.txt
View source
  1. Schema module
  2. PREREQUISITES
  3. Drupal 5.0
  4. OVERVIEW
  5. The Schema module provides Drupal with a database schema API, a method
  6. for modules to declare their database tables in structured data rather
  7. than via CREATE TABLE statements, and a means for Drupal to inspect
  8. and reflect on its own database structure.
  9. THIS MODULE IS IN PRE-ALPHA USE AT YOUR OWN RISK RELEASE! It is
  10. currently for demonstration, testing, and development purposes only.
  11. You've been warned.
  12. INSTALLATION
  13. Install and activate Schema like every other Drupal module.
  14. ADMINISTRATOR USAGE
  15. As an administrator, Schema will show you information about tables
  16. that exist in your database and how they match or do not match up with
  17. the schema information defined by modules. Visit Administer >> Site
  18. building >> Schema for this information. Note that these pages are
  19. information-only; there are no actions you can perform from them.
  20. *** IMPORTANT NOTE: Schema expects to find the standard Drupal tables
  21. (declared by system.module) defined as of version 1022 (Drupal 5 head
  22. as of April 14, 2007). If you are using a different version of Drupal
  23. 5, it will report "mismatches" on the Report page.
  24. MODULE DEVELOPER USAGE
  25. Currently, don't use Schema, as everything about it is subject to
  26. change.
  27. Suppose your module named mymodule wants to use a single simple table
  28. named mytable. Define hook_schema() in your .module file:
  29. function mymodule_schema() {
  30. $schema['#version'] = 1;
  31. $schema['mymodule_mytable] = array(
  32. 'name' => 'mytable',
  33. 'cols' => array(
  34. 'id' => array('type' => 'int', 'not null' => '1'),
  35. 'val => array('type' => 'varchar', 'length' => 255, 'not null' => '1'),
  36. ),
  37. 'keys' => array('PRIMARY' => array('id')));
  38. return $schema;
  39. }
  40. Now, in your .install file, use Schema to install and uninstall your
  41. tables:
  42. function schema_install() {
  43. $my_schema = module_invoke('mymodule, 'schema');
  44. schema_create_schema($my_schema);
  45. }
  46. function schema_uninstall() {
  47. $my_schema = module_invoke('mymodule, 'schema');
  48. schema_drop_schema($my_schema);
  49. }
  50. That's it! Except, of course, this is pre-alpha code, so that
  51. probably isn't it.
  52. TO DO
  53. - Database engines for Postgres and other DBMS's.
  54. - The above .install code actually won't work because mymodule.module
  55. is not loaded when mymodule_install() is run (or is it?).
  56. - Define join relationships, use them for world domination.
  57. AUTHOR
  58. Barry Jaspan
  59. firstname at lastname dot org