MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / ensureSchema

Function ensureSchema

cloud-sql/postgres/knex/index.js:143–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141};
142
143const ensureSchema = async pool => {
144 const hasTable = await pool.schema.hasTable('votes');
145 if (!hasTable) {
146 return pool.schema.createTable('votes', table => {
147 table.increments('vote_id').primary();
148 table.timestamp('time_cast', 30).notNullable();
149 table.specificType('candidate', 'CHAR(6)').notNullable();
150 });
151 }
152 logger.info("Ensured that table 'votes' exists");
153};
154
155const createPoolAndEnsureSchema = async () =>
156 await createPool()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected