summaryrefslogtreecommitdiffstats
path: root/scripts/prefix.sh
blob: f15476a00d490fa74a7fa9ef80d09b7d4d984bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh

if [ $# != 2 ]; then
  cat >&2 << EOH
This is Drupal database prefixer.

Usage:
  $0 prefix original_db.sql >prefixed_db.sql

- all tables will prefixed with 'prefix'
EOH

exit 1;
fi

PREFIX=$1;
sed "s/\`//g;
     s/^CREATE TABLE /CREATE TABLE $PREFIX/;
     s/^INSERT INTO /INSERT INTO $PREFIX/;
     s/^REPLACE /REPLACE $PREFIX/;
     s/^ALTER TABLE /ALTER TABLE $PREFIX/;
     s/^CREATE SEQUENCE /CREATE SEQUENCE $PREFIX/;
     s/^ALTER SEQUENCE /ALTER SEQUENCE $PREFIX/;
     s/^CREATE INDEX \(.*\) ON /CREATE INDEX $PREFIX\\1 ON $PREFIX/;
     s/^CREATE UNIQUE INDEX \(.*\) ON /CREATE UNIQUE INDEX $PREFIX\\1 ON $PREFIX/;
     s/^UPDATE \(.*\) SET /UPDATE $PREFIX\\1 SET /;
     s/^DROP TABLE IF EXISTS /DROP TABLE IF EXISTS $PREFIX/;
     s/ DEFAULT nextval('/ DEFAULT nextval('$PREFIX/;
     " $2