AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import {
createTrigger,
TriggerStrategy,
AppConnectionValueForAuthProperty,
} from '@activepieces/pieces-framework';
import {
DedupeStrategy,
Polling,
pollingHelper,
} from '@activepieces/pieces-common';
import { snowflakeAuth } from '../auth';
import { snowflakeCommonProps, toAuthValue, withSnowflake } from '../common';
import { newColumnOutputSchema } from '../common/output-schemas';
import { qualifiedName } from '../common/sql';
type NewColumnProps = {
database: string;
schema: string;
table: string;
};
const props = {
database: snowflakeCommonProps.database,
schema: snowflakeCommonProps.schema,
table: snowflakeCommonProps.table,
};
const polling: Polling<
AppConnectionValueForAuthProperty<typeof snowflakeAuth>,
NewColumnProps
> = {
strategy: DedupeStrategy.LAST_ITEM,
items: async ({ auth, propsValue }) => {
const { table } = propsValue;
if (!table) return [];
{
const result = (
await withSnowflake({
auth: toAuthValue(auth),
fn: (session) =>
session.query({
sql: `DESCRIBE TABLE ${qualifiedName({
value: table,
label: 'Table',
})}`,
}),
})
).rows;
// Columns are returned in ordinal-position order (lowest first).
// New columns are always appended at the end → highest index = newest.
// Reverse so that LAST_ITEM deduplication stores the newest column's id
// and emits only columns added after that position on subsequent polls.
return result
.map((col, index) => ({
id: index + 1,
data: {
column_name: col['name'],
data_type: col['type'],
nullable: col['null?'],
default_value: col['default'],
primary_key: col['primary key'],
unique_key: col['unique key'],
comment: col['comment'],
position: index + 1,
table,
},
}))
.reverse();
}
},
};
export const newColumnTrigger = createTrigger({
auth: snowflakeAuth,
name: 'new_column',
displayName: 'New Column',
description:
'Triggers when a new column is added to the selected table. Checked by polling every few minutes.',
classification: 'READ',
outputSchema: newColumnOutputSchema,
aiMetadata: {
description:
"Fires when a new column is added to the selected Snowflake table, detected by polling the table's column list and emitting columns appended since the last check. Each newly added column produces one event with its name, data type, and constraints.",
},
props,
sampleData: {
column_name: 'EMAIL',
data_type: 'VARCHAR(256)',
nullable: 'Y',
default_value: null,
primary_key: 'N',
unique_key: 'N',
comment: '',
position: 5,
table: 'MY_DATABASE.PUBLIC.CUSTOMERS',
},
type: TriggerStrategy.POLLING,
async test(context) {
return await pollingHelper.test(polling, context);
},
async onEnable(context) {
await pollingHelper.onEnable(polling, context);
},
async onDisable(context) {
await pollingHelper.onDisable(polling, context);
},
async run(context) {
return await pollingHelper.poll(polling, context);
},
});