Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 97 lines (71 sloc) 3.776 kb
6faba4f @olivier-m Initial commit
authored
1 ================
2 Django appschema
3 ================
4
5 What is it?
6 ===========
7
4c1c3dd @olivier-m Updated README
authored
8 Django Appschema is born from the idea proposed by *tidbids* on `SaaS with
9 Django and PostgreSQL
10 <http://tidbids.posterous.com/saas-with-django-and-postgresql>`_ and `SaaS
11 with Django and PostgreSQL Schemas
12 <http://tidbids.posterous.com/saas-with-django-and-postgresql-schemas>`_.
6faba4f @olivier-m Initial commit
authored
13
4c1c3dd @olivier-m Updated README
authored
14 The main idea is to isolate customer's data in different schema. One customer
15 = one schema. There are very good explanations on why schemas and what it
16 could bring to your SaaS application on `this thread on Hacker News
17 <http://news.ycombinator.com/item?id=1565674>`_.
6faba4f @olivier-m Initial commit
authored
18
3ae8dc2 @olivier-m Typo in README
authored
19 How it works?
20 =============
6faba4f @olivier-m Initial commit
authored
21
4c1c3dd @olivier-m Updated README
authored
22 On the running side, schema isolation is quite easy, set up a middleware that
23 make dispatch, a signal and *voilà* (almost).
6faba4f @olivier-m Initial commit
authored
24
4c1c3dd @olivier-m Updated README
authored
25 Django Appschema creates a table containing a ``public_name`` (could be FQDN
26 or whatever your middleware decides) and a associated schema. This table
27 should be shared by all schemas you'll create.
6faba4f @olivier-m Initial commit
authored
28
4c1c3dd @olivier-m Updated README
authored
29 Now the complicated part. Performing syncdb on multiple schemas could be a bit
30 difficult, specially if you want to share some apps and isolate some others
31 (or both).
6faba4f @olivier-m Initial commit
authored
32
4c1c3dd @olivier-m Updated README
authored
33 On your configuration file, you'll add ``APPSCHEMA_SHARED_APPS`` which is a
34 list containing the apps you want to share. Basically, shared apps tables are
35 created in ``public`` schema.
6faba4f @olivier-m Initial commit
authored
36
4c1c3dd @olivier-m Updated README
authored
37 Appschema will alway be a shared app. If installed, South will be both shared
38 and isolated.
6faba4f @olivier-m Initial commit
authored
39
4c1c3dd @olivier-m Updated README
authored
40 Appschema comes with modified versions of ``syncdb`` and ``migrate`` that will
41 perform required operations on schemas.
6faba4f @olivier-m Initial commit
authored
42
4c1c3dd @olivier-m Updated README
authored
43 Another management command called ``createschema`` allows you to create a new
44 schema and performs syncdb (and migrate if available) on the new created
45 schema.
6faba4f @olivier-m Initial commit
authored
46
c3dc1e3 @olivier-m Added schematemplate management command and a PostgreSQL stored procedur...
authored
47 Schema creation from your web app
48 ---------------------------------
6faba4f @olivier-m Initial commit
authored
49
4c1c3dd @olivier-m Updated README
authored
50 If you look at the code, you'll find a function called ``new_schema``. You
51 could be tempted to use it directly in your web app (for registration
52 purpose). DON'T. NEVER. SERIOUSLY. In order to run properly, commands modify
53 INSTALLED_APPS and the Django apps cache during execution. What is not an
54 issue during a management command could become a nightmare in a runing Django
55 process.
6faba4f @olivier-m Initial commit
authored
56
c3dc1e3 @olivier-m Added schematemplate management command and a PostgreSQL stored procedur...
authored
57 A first solution comes with ``schematemplate`` management command. This
58 command creates a temporary schema, executes ``pg_dump`` on it and prints the
59 result on standard output. It replaces the temporary schema name by a
60 substitution pattern named ``%(schema_name)``. You can store this result for
61 later use. Runing ``schematemplate`` command on each deployment is a good
62 idea.
63
8822a17 @olivier-m Added models.new_schema_from_template. Reached 0.4
authored
64 New: A function called ``new_schema_from_template`` (in ``appschema.models``)
65 performs the schema creation based on this template file.
66
c3dc1e3 @olivier-m Added schematemplate management command and a PostgreSQL stored procedur...
authored
67 Alternative: clone_schema stored procedure
68 ------------------------------------------
69
70 Appschema provides a PostgreSQL (version 8.4 only) stored procedure called
71 ``clone_schema(source, destination)`` (In contrib directory). It makes a copy
72 of ``source`` schema on ``destination``. Create a master schema and you could
73 use it as a source for ``clone_schema``. As this procedure is still a work in
74 progress, you may prefer using the ``schematemplate`` way.
75
76 Please note
77 ===========
78
79 This **highly experimental** app works **only for PostgreSQL**.
6faba4f @olivier-m Initial commit
authored
80
4c1c3dd @olivier-m Updated README
authored
81 You'll find a FqdnMiddleware which switchs schema based on the host name of
82 the HTTP request. Feel free to make your own based on your needs.
6faba4f @olivier-m Initial commit
authored
83
84 If you find bugs (and I'm sure you will), please report them.
4c1c3dd @olivier-m Updated README
authored
85
86 It wasn't test with multiple databases support and I'm not sure it works in
87 such case.
88
89 Be careful with foreign keys. As you can make any foreign key you want in
90 isolated app models referencing shared one, the opposite is not true.
91
92 License
93 =======
94
1bef5f1 @olivier-m README fix
authored
95 Django appschema is released under the MIT license. See the LICENSE
4c1c3dd @olivier-m Updated README
authored
96 file for the complete license.
Something went wrong with that request. Please try again.