You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/cookbook/working-with-existing-databases.markdown
+42-15Lines changed: 42 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,42 +5,69 @@ title: Working With Existing Databases
5
5
6
6
# Working With Existing Databases #
7
7
8
-
The following topics are targeted for developers who already have a working database solution in place, but would like to use Propel to work with the data. For this case, Propel provides a number of command-line utilities helping with migrations of data and data structures.
8
+
The following topics are targeted for developers who already have a working database solution in place, but would like to use Propel to work with the data. Propel provides command-line utilities to help migrate database structures into Propel's abstract schema format, enabling model generation and cross-database support.
9
9
10
10
## Working with Database Structures ##
11
11
12
-
Propel uses an abstract XML schema file to represent databases (the [schema](/documentation/reference/schema.html)). Propel builds the SQL specific to a database based on this schema. Propel also provides a way to reverse-engineer the generic schema file based on database metadata.
12
+
Propel uses an abstract XML schema file to represent databases (see the [XML Schema Format](/documentation/reference/schema.html)). Propel builds SQL for your target database based on this schema — and can also reverse-engineer the schema file based on existing database metadata.
13
13
14
14
### Creating an XML Schema from a DB Structure ###
15
15
16
-
To generate a schema file, create a new directory for your project & specify the connection information in your *configuration file* for that project. For example, to create a new project, `legacyapp`, follow these steps:
16
+
Propel provides the `database:reverse` command to reverse-engineer your database into a `schema.xml` file. This is useful when integrating with a legacy database or starting a project based on an existing schema.
17
17
18
-
1. If your database has some third party application tables, you can [add](/documentation/reference/configuration-file.html#exclude-tables) them to the `exclude_tables` configuration node.
18
+
To generate the schema:
19
+
20
+
1. If your database includes tables you don’t want to include (e.g. third-party ones), [exclude them](/documentation/reference/configuration-file.html#exclude-tables) in the configuration using `exclude_tables`.
19
21
20
22
2. Go to the `legacyapp` project directory anywhere on your filesystem:
21
23
22
24
```bash
23
25
$ cd legacyapp
24
26
```
25
27
26
-
3. Run the `reverse` task to generate the `schema.xml` specifying your database
27
-
credentials:
28
+
3. Run the `database:reverse`command with your DSN or connection name:
4. Pay attention to any errors/warnings issued during the task execution and then
38
-
examine the generated `schema.xml` file to make any corrections needed.
67
+
`database:reverse` does not reverse-engineer views, materialized views, or enum types in PostgreSQL. These structures are not currently supported by Propel as first-class schema objects. If you want to use a view within Propel, you can manually define it as a `<table>` with `skipSql="true"` to generate read-only model/query classes.
39
68
40
-
5. _You're done!_ Now you have a `schema.xml` file in the `legacyapp/generated-reversed-database` project
41
-
directory. You can now run the default Propel build to generate all the classes.
42
69
43
-
The generated `schema.xml` file should be used as a guide, not a final answer. There are some datatypes that Propel may not be familiar with; also some datatypes are simply not supported by Propel (e.g. arrays in PostgreSQL). Unfamiliar datatypes will be reported as warnings and substituted with a default VARCHAR datatype.
70
+
Note: database:reverse replaces the old reverse commandin Propel 2.x. The alias reverse is still available but may be deprecated infuture versions.
44
71
45
72
>**Tip**The reverse engineering classes may not be able to provide the same level of detail for all databases. In particular, metadata information for SQLite is often very basic since SQLite is a typeless database.
0 commit comments