Created a new entity column on a table that looks like this:
@Column({
type: 'geography',
spatialFeatureType: 'Point',
srid: 4326,
nullable: true,
})
geography: Point
I am configuring the test module using NestJS and TypeORM. Based on the source code here and here, it seems as though by default, TypeORM installs Postgis if a geography column is detected, but I keep getting this error: QueryFailedError: type "geography" does not exist.
Here is the configuration I have for the test module:
export const testingModule = (providers: Provider[]) => {
return Test.createTestingModule({
imports: [
TypeOrmModule.forRootAsync({
useFactory: () => {
type: 'postgres',
url: getEnv('DATABASE_URL'),
dropSchema: true,
autoLoadEntities: true,
synchronize: true,
logging: false,
namingStrategy: new SnakeNamingStrategy(),
keepConnectionAlive: false,
},
dataSourceFactory: async (options: any) => ... // returns datasource
},
}),
TypeOrmModule.forFeature(
Location,
),
EventEmitterModule.forRoot(),
],
providers,
})
}
Am I missing something here?
I also tried using the dataSourceFactory to explicitly add Postgis using the data source, but I believe this isn't happening synchronously, so I think the line to install Postgis happens after the schema is created (which contains the geography column, hence the error).
This works as designed in our regular environments, but unable to get this to play nice with the testing module from NestJS.
Here's how I went about it. I first added
manualInitializationto my data source config and set it totrue.This preventsTypeOrmModulefrom automatically initializing the database.I did that because I wanted to initialize the database manually to prevent this:
In my test file, in the
beforeAllhook, I create thepostgisextension before manually initializing the database as shown below:I ran into the error:
QueryFailedError: extension "postgis" is not available.The extension must first be installed on the system where PostgreSQL is running.So I ran
brew install postgis(I'm on a Mac. It installed a ton of packages.), and then I reran the test.