

ro: Using this endpoint only SELECT queries are allowed.Each endpoint may have access to one or more schemas (databases), and may have different levels of permission for each. endpoints: This is a nested YAML object defining different credentials.If not specified, a single database named main will be created. databases: This is a YAML array listing the databases that should be created.Under the configuration key of your service there are two additional keys: To do so requires defining multiple endpoints. It’s possible to define multiple databases as well as multiple users with different permissions. If you are using version 10, 11, 12, 13, or later of this service, Taking a backup or a database export before doing so is strongly recommended. It will overwrite data already in your database. Importing a database backup is a destructive operation. You can also access it from your app container via SSH.įrom your relationship data, you need: username, host, and port. close () return table except Exception as e : return e Access the service directlyĪccess the service using the Platform CLI by running platform sql. execute ( sql ) # Close communication with the database cur. format ( record, record ) table += ''' \n \n ''' # Drop table sql = "DROP TABLE People" cur. RAISE notice 'drop index %', quote_ident(index_names.index_name) ĮXECUTE 'drop index ' || quote_ident(index_names.Package examples import ( "database/sql" "fmt" _ "/lib/pq" psh "/platformsh/config-reader-go/v2" libpq "/platformsh/config-reader-go/v2/libpq" ) func UsageExamplePostgreSQL () string \n '''. || ' drop constraint ' || the_constraint_name RAISE notice 'alter table % drop constraint %',Įxecute 'alter table ' || this_table_name WHERE CONSTRAINT_SCHEMA = current_schema() SELECT CONSTRAINT_NAME INTO the_constraint_nameįROM information_nstraint_column_usage RAISE notice 'migrating table %', this_table_name DO $$įOREACH this_table_name IN array table_names It also works for multiple tables in one go.

So the following is sql that will delete one constraint and all indexes on the text field before converting to a uuid field. And as I discovered, Django likes to use your migrations to created randomly named indexes on your fields while running tests, so your tests will fail if you just delete and then recreate a fixed name index or two. The basic command you want looks like:Īlter table tablename alter column uuid type uuid using uuid::uuid īut the reason we are here is because of indexes. Now for the real tricky part, where we actually perform the migration. I opted to put the sql into a separate file and then load in with the following python code: sql_path = os.path.join(os.path.dirname(os.path.abspath(_file_)), '0001.sql') Now you'll need to provide some SQL commands for that sql_commands variable. This allows you to provide a custom migration, but keep Django informed about what's happened to the database schema. The same techniques would work for an integer to uuid conversion.īased on a comment, I've added the full solution here:ĭjango will most likely create a migration for you that looks something like: class Migration(migrations.Migration):įield=models.UUIDField(db_index=True, unique=True),įirst, put the auto created migration operations into a RunSQL operation as the state_operations parameter. I had to convert from text to uuid type, and from a Django migration, so after solving this I wrote it up at in case that helps anyone. I solved the problem by first altering the field into a CHAR type and then into UUID type. Just if someone comes across this old topic. You need the UUID module installed: CREATE EXTENSION "uuid-ossp" ALTER TABLE tableA ALTER COLUMN colA SET DATA TYPE UUID USING (uuid_generate_v4()) Ī better approach is usually to add a uuid column, then fix up any foreign key references to point to it, and finally drop the original column. It permanently throws away the old values in colA. If you want to generate new UUIDs to replace the integers entirely, and if there are no existing foreign key references to those integers, you can use a fake cast that actually generates new values.ĭo not run this without a backup of your data. You can't just cast an int4 to uuid it'd be an invalid uuid, with only 32 bits set, the high 96 bits being zero.
